[jdom-interest] Namespace?
dfeather at oreillyauto.com
dfeather at oreillyauto.com
Tue Jul 10 11:52:56 PDT 2001
>
> I am trying to add the following namespaces to the FILE
root node
> and am having limited success. I went to search the mail list archives
but
> they appear to be out of commission for the time being. It seems the
> following should be fairly simple but it is not clear to me from the
javadoc
> how this is accomplished. Could some kind soul please send me a code
> snippet that addresses my needs?
>
> Thanks
> -Gary
>
>
> <?xml version = "1.0" encoding = "UTF-8"?>
> <FILE xmlns:xsi = "http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation =
"file:///C:/Documents/832BP_SCHEMAV04.XSD">
> <ROUTING>
> </ROUTING>
> </FILE>
This is what I do:
-----------8<--SNIP-----------------
Element newRoot = new Element("FILE");
Namespace xmlns =
Namespace.getNamespace("xsi","http://www.w3.org/2000/10/XMLSchema-instance");
newRoot.addNamespaceDeclaration(xmlns);
Attribute xsiAttrib = new Attribute("noNamespaceSchemaLocation","file:///C:/Documents/832BP_SCHEMAV04.XSD",xmlns);
newRoot.addAttribute(xsiAttrib);
-----------8<--SNIP-----------------
That works for me. There may be a better way. Anyone? This is what I use
in JDOM B6 BTW. I have not yet grabbed B7 (shame on me). I don't know if
B7 will require any changes to this.
Dan Feather
Programmer/Analyst
O'Reilly Automotive, Inc.
417-862-2674 x8949
dfeather at oreillyauto.com
More information about the jdom-interest
mailing list