Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Problem creating the right namespace.

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Christian-Josef Schrattenthaler <hotline AT software-agentur.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Problem creating the right namespace.
  • Date: Wed, 25 Feb 2009 06:28:46 -0800

Christian-Josef Schrattenthaler wrote:
Hi!


I have to use xml files for a little Java project. These files are
generated over the Java application itself, but I have to use an
external xml schema.


The root element must look like:


<rootelement xmlns=http://... xmlns:xsi=http://...
xsi:schemaLocation="http://...";>


I did:


Element xmlRoot = new Element("onlv",
"http://www.oenorm.at/schema/A2063/2009-01-15";);

xmlRoot.addNamespaceDeclaration("xsi",
"http://www.w3.org/2001/XMLSchema-instance";);


You don't need to add an explicit namespace declaration. Instead just add

Attribute a = new Attribute("xsi:schemaLocation", "http://www.w3.org/20001/schema-instance";, "foo/bar");

But now I don't know how to add 'xsi:schemaLocation="http://...";', and I
have an empty (xmlns="") attribute on each child element I add to the
root element.


Every element you create in a namespace shoudl be given its namespace in Java. e,g,

Element foo = new Element("foo", "http://www.oenorm.at/schema/A2063/2009-01-15";);

XOM will figure out where to put the namespace delclarations. You only need to call addNamespaceDeclaration if you have namespaces in attribute values that do not appear in element content in the same scope, or if you want to move a namespace declaration higher in the hierarchy (usually to the root element) than it would naturally appear.


--
Elliotte Rusty Harold elharo AT metalab.unc.edu
Refactoring HTML Just Published!
http://www.amazon.com/exec/obidos/ISBN=0321503635/ref=nosim/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page