[jdom-interest] Schema Validation not working

Colin Goudie colin.goudie at minesuite.com
Tue Feb 17 16:30:24 PST 2004


I store a modules.xml file in a jar file in /xsd/modules.xml. I also have a
modules.xsd file in that directory too. Note, it is all stored in a Jar
file.

My xsd file has a targetNamespace and xmlns
="http://www.maptek.com.au/rpuwin" but a
xmlns:xs="http://www.w3.org/2001/XMLSchema"

My xml file has a xmlns="http://www.maptek.com.au/rpuwin"


No in code I do this
builder = new SAXBuilder();

builder.setFeature("http://apache.org/xml/features/validation/schema",
true);

builder.setProperty("http://apache.org/xml/properties/schema/external-schema
Location",

getClass().getResource(MODULE_XSD_FILE).toString()); // MODULE_XSD_FILE =
/xsd/modules.xsd

document = builder.build(getClass().getResource(MODULE_FILE)); //MODULE_FILE
= /xsd/moudles.xml

Namespace namespace =
Namespace.getNamespace("http://www.maptek.com.au/rpuwin");

Element root = document.getRootElement();
System.out.println("Got root = " + root.getName());
Iterator iter = root.getChildren("Module", namespace).iterator();
while (iter.hasNext()) {
	Element elem = (Element)iter.next();
      System.out.println("Module name = " + elem.getAttributeValue("name"));
}

However, my problem is that it isnt validating. I can screw the xml file up
and I get no errors or anything. Is this right? Should build() call fail?

I'm guessing I'm doing something wrong with the namespaces or something.

Thanks


Colin Goudie (B.Comp Sci)
MineSuite Engineer
colin.goudie at minesuite.com
http://www.maptek.com.au




More information about the jdom-interest mailing list