[XOM-interest] Defining schema location

Elliotte Harold elharo at metalab.unc.edu
Mon Mar 10 23:28:09 EDT 2008


Daniel Garrido wrote:
> Hi!
> 
> I'd like to know how to create the root element with the following definitions:
> 
> <cns:Constraints xmlns:cns="http://www.example.org/Constraints"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:schemaLocation="http://www.example.org/Constraints
> ../../../Structures/Constraints/Constraints.xsd ">
> ...
> </cns:Constraints>
> 
> I've already been able to write a xml with all namespace definitions,
> but not with the schemaLocation. Nextly i'll post the code i'm using:
> 
>                 String namespace = "http://www.example.org/Constraints";
> 		String prefix = "cns:";
> 		Element root = new Element(prefix + "Constraints", namespace);
> 		root.addNamespaceDeclaration("xsi",
> "http://www.w3.org/2001/XMLSchema-instance");
> 

There's no code there to add the attribute. You need to add the 
xsi:schemaLocation attribute, not the namespace declaration. (Adding the 
declaration won't hurt, but it's njot necessary.)


-- 
Elliotte Rusty Harold  elharo at metalab.unc.edu
Java I/O 2nd Edition Just Published!
http://www.cafeaulait.org/books/javaio2/
http://www.amazon.com/exec/obidos/ISBN=0596527500/ref=nosim/cafeaulaitA/


More information about the XOM-interest mailing list