Xsd nillable

In one of my current projects we are sending data to another company. Because xml is somewhat the standard for exchanging data these days I wrote a small java app using velocity to generate the xml files. Sure I could have used Oracle’s features to create an xml file but if you use that feature you could just as well give them an ASCII file imho.

So I started by creating the xml schema (xsd). Because some fields can be empty I some nullable fields. And that’s where the issues started. We have some dateTime fields that can be null so I thought spitting out a <date /> tag or <date></date> would do the trick!!! Biep error, after some googling and reading a lot I came to the conclussion that I had to output this : <date xsi:nil=”true”/> . Stupid if you ask me, but hey it now works.

I wrote a small velocity macro that I called:

#macro( xmlempty $value $tag $cdata)
#if ($!value == "" || !$value)
< $tag xsi:nil="true"/>
#elseif ($cdata == "true")
< $tag>< ![CDATA[$!value]]>
#else
< $tag>$!value
#end
#end

Works nice I have to say. The program was straight forward, a file that contains key value pairs. The key was the velocity template, the value was the query. I ran the query, retrieved the ResultSet cursor and while iterating it for every iteration I called upon the template that merged with my UTF-8 filewriter.

What kinde surprised me was the lack of good xsd/xml editors in the opensource. I tried the ones that were bundled with our myeclipse environment but they were more a pain than a gain. (omg lame!) So in the end I installed xmlspy and asked for a testing license. I have to say they have a really good product, but who wants to pay 600 € for an xml editor. People come on, even ms visual studio .net 2005 pro only costs 750. They also have xml support built in, for that I’m willing to pay because of the added value but not for an xml editor. There are only a couple of things I need from an xml editor.

  • xsd code completion
  • Is my xsd valid
  • Why not, with linenumber error
  • Xml code completion using the provided xsd
  • Is my xml valid
  • Why not, with linenumber error
  • Maybe an xpath,xquery and xsl features

That should be sufficient. Hmm looks like a project for the future 🙂

One Reply to “Xsd nillable”

  1. I’m struggling through XSD validation now and am using my IntelliJ IDE for on-the-fly validation. Maybe that will meet your requirements? If cost is an issue, they have an open-source “community edition” now that might have this support (I’m using an older paid version).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.