How to generate simple-xml java annotated object from xsd schema

Ok, so I’ve searched stackoverflow and found unanswered sub-topics regarding this issue, that’s why I’d like to have this question clearly pointed out:

Is there any tool that will generate the Simple Xml library‘s annotated java class from an xsd schema?

I received a couple of xsd files describing the objects returned by a restful web-service someone else has developed and currently I’ve translated those schemas to the simple-xml annotated classes. Those will be used in my Android app. It would be better to just automatically synchronize any changes to the schemas and regenerate the classes from them. The ws guys have a repository of Jackson compliant classes for those schemas, however I don’t want to use Jackson – I’m using Spring Android, so I’d prefer to go with the preferred simple-xml. There must be something that does the trick like JAXB’s xjc tool.

If there is no such tool – can you think of any traps in implementing a script that generates a .java file for simple-xml from the schema? Maybe any hints for tools worth extending that would just require defining what annotations to generate and when?

In advance – thanks a lot for your answers!


I do not believe that JAXB can be used on Android because of missing package requirements (see here), especially with earlier versions of the Android API. What you could do instead is send your XSD through xjc and get JAXB class output and then write a script to convert the JAXB annotations into the equivalent Simple XML annotations. This should do exactly what you were looking for.

However, ideally, and if you had the time, you could check out the source for xjc and extend it to be able to output JAXB or Simple annotated classes.


Does my JDBC connection to the database use SSL or not?

How can one know if the JDBC connection to an SQL server is secure (i.e. uses SSL) or not?

Is it obvious for example from the URL. Do all JDBC drivers support SSL connections to the database server, or does the use of SSL just depends on the specific database vendor?


Do all jdbc drivers support ssl connection to db server and the use of ssl just depends on a specific db vendor?

Support for SSL/TLS is not mandated in the JDBC specification. So you cannot expect it in every driver.

SSL configuration on the database server could be inferred from the JDBC URL, but this need not be deterministic. In the case of Oracle, if you notice that the URL contains a connection string that indicates that the protocol in use is TCPS instead of TCP, which points to the use of SSL/TLS. If you are doing this to validate a security configuration, I would call you sloppy.

It is unwise to verify the client configuration alone to determine if the database server accepts connections over SSL, especially if non-SSL connections are disallowed. The mechanisms for verifying the SSL/TLS configuration will vary from database to database, but there would be appropriate security guides for configuring the database in each case.

If you want to do a quick test however, to verify if connectivity is over SSl/TLS, then all you have to know is that SSL/TLS secured connections are initiated with a handshake. If you do not see any, then your driver is not using SSL/TLS. You’ll need to sniff network traffic for this (make sure that you have authorization to do so). Of course, it would take longer to establish the case if a connection pool were in use, for the physical connections in the pool might be reused time and again (without new connections being setup). Likewise, you might also find nmap to be useful, but I’ve never used it for this purpose.


Store a value in ViewBag from javascript

How can I store a value in the ViewBag accessing it from javascript?


You cannot store a value in ViewBag from javascript. ViewBag is a server side concept and exists only on the server. Javascript runs on the client. As far as storing some data from ViewBag into a javascript variable is concerned you could use the following:

<script type="text/javascript">
    var foo = @Html.Raw(Json.Encode(ViewBag.FooBar))

Now this being said I always advice people against using ViewBag/ViewData in ASP.NET MVC. I recommend using strongly typed view and view models. So your code will look like this:

@model MyViewModel
<script type="text/javascript">
    var foo = @Html.Raw(Json.Encode(Model))

Month name as a string

I’m trying to return the name of the month as a String, for instance “May”, “September”, “November”.

I tried:

int month = c.get(Calendar.MONTH);

However, this returns integers (5, 9, 11, respectively). How can I get the month name?


Use getDisplayName.

For earlier API’s use String.format(Locale.US,"%tB",c);


Elegant clean way to include HTML in JavaScript files?

I’m building a small app with a few modal dialog windows. The windows require a tiny bit of HTML. I’ve hard coded the window HTML in the javascript library but am not thrilled with this solution. Is there a more elegant way to do this? It seems that JavaScript doesn’t have multi line strings/heredoc syntax.

var html = "<div id='email_window'><h2>Email Share</h2><div>";
html = html + "<form action='javascript:emailDone();' method='post'>";
html = html + "<div><label for='to'>To</label><input id='to' type='text'></div>";
html = html + "<div><label for='from'>From</label><input id='from' type='text' value='" + email + "'></div>";
html = html + "<div><label for='subject'>Subject</label><input id='subject' type='text' disabled='disabled' value='" + subject + "'></div>";
html = html + "<div><label for='body'>Body</label><input id='body' type='text' disabled='disabled' value='" + body + "'></div>";
html = html + "<div><input type='submit' value='Send'><input type='button' value='Cancel' onClick='javascript:$.fancybox.close();'></div>";
html = html + "</form></div>";


Added to clarify the original message-

Any solution can’t use Ajax/XHR to pull in the template file because the javascript library will be on a different domain that the html file it’s included in It’s a little like ShareThis. The library will be included on a number of different sites and attached to the onClick event of any anchor tag inside divs with attribute sharetool=”true”.

For example: - index.html
<script type="text/javascript" src=""></script>
<div sharetool="true">


Templates. Pick your poison

Either inline them as script blocks or load them using ajax as external resources.

I personally use EJS as external template files and just get EJS to load them and inject them into a container with json data bound to the template.

new EJS({ 
    url: "url/to/view"
}).update('html_container_name', {
    "foobar": "Suprise"

And then view files use generic view logic.

// url/to/view
<p> <%=foobar %></p>
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..