SV: [jdom-interest] Schema Validation not working
Per Norrman
pernorrman at telia.com
Tue Feb 17 16:56:41 PST 2004
Hi,
try creating a "validating" SAXBuilder.
... = new SAXBuilder(true);
/pmn
> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org] För Colin Goudie
> Skickat: den 18 februari 2004 01:30
> Till: jdom-interest at jdom.org
> Ämne: [jdom-interest] Schema Validation not working
>
>
> 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/e
> xternal-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
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
More information about the jdom-interest
mailing list