[jdom-interest] Re: xsi:nil

Scott Ellis scotey at pacbell.net
Sat Oct 30 17:00:50 PDT 2004


Hey, thanks a lot! It works and I can continue (thank goodness).  Here is
the code I use:

Attribute attr = new Attribute( "nil", "true" );
attr.setNamespace( Namespace.getNamespace( "xsi",
"http://www.w3.org/2001/XMLSchema-instance" ) );
child.setAttribute( attr );

Thanks again!

Scott

----- Original Message ----- 
From: "Jason Hunter" <jhunter at xquery.com>
To: "Scott Ellis" <scotey at pacbell.net>
Cc: <jdom-interest at jdom.org>
Sent: Saturday, October 30, 2004 11:32 AM
Subject: Re: [jdom-interest] xsi:nil


> 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