[jdom-interest] xsi:nil

Jason Hunter jhunter at xquery.com
Sat Oct 30 11:32:24 PDT 2004


The prefix "xsi" doesn't mean anything without a URI associated with it, 
so you have to use the Namespace object to make the association.

Namespace xsi = Namespace.getNamespace("xsi", "http://...");
Element e = new Element("SampleElement);
e.setAttribute("nil", "true", xsi);

-jh-

Scott Ellis wrote:

> Hi,
>  
> I'm not sure if I'll get replies to this, so please send me an responses.
>  
> I am one step away from using schema to validate my xml, xml that is 
> generated by JDOM, but I have one last problem.  I cannot for the life 
> of me figure out how to specify xsi:nil="true" as an element attribute.  
> I NEED this so that my incoming xml can specify to nullify the data in 
> my text node, because if I don't allow nulls, then types that are 
> specified as xs:dateTime for instance are rejected by the parser because 
> it assumes a date is there and won't accept empty values.  I do not find 
> it acceptable to change this to xs:string.
>  
> So, here is my sample code.  I am no guru, and am one step removed from 
> the apes as far as my knowledge goes, so go easy on me.
>  
> org.jdom.Element elem = new Element( "SampleElement" );
> elem.setAttribute( "xsi:nil", "true" );
>  
> That's what I'd like to do.  This throws an exception because I'm not 
> allowed to have a colon in the attribute name.  So I fooled around with 
> setting the Namespace to xsi, and I won't bother telling you what the 
> exception was.  I'm not even sure if "xsi" is a namespace, or is a 
> publicId or a systemId.  Don't know.  Maybe you can help.  But whatever 
> it is, I need to know how to get it done with JDOM.
>  
> Can anybody help?
>  
> Scott
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com


More information about the jdom-interest mailing list