Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

SV: [jdom-interest] Schema Validation not working

Per Norrman

2004-02-17

Replies:

Hi,

try creating a "validating" SAXBuilder.
... = new SAXBuilder(true);

/pmn


> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin@(protected)
> [mailto:jdom-interest-admin@(protected)
> Skickat: den 18 februari 2004 01:30
> Till: jdom-interest@(protected)
> Ä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@(protected)
> http://www.maptek.com.au
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr@(protected)

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.