From: Jeff M. <je...@mk...> - 2003-02-07 11:12:45
|
Cheers, still not got the the bottom of this. But, have couple of points to note. j2sdk1.4.1 uses crimson as it's parser not xerces. This means you need to call XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl"= ); Another point which may help (need to look at this cause it's a bit naf at the moment) it that error messages from parsing the can only be displayed by calling toString on the Validator. So you probably need to write tests like this. String generated=3D"BookXsdGenerated.xml"; Validator validator =3D new Validator(new FileReader(generated)); if(!validator.isValid()){ fail(validator.toString()); } This then gives you details of the failure (Might add a assertValid() met= hod in the future). At the moment when I try this I get the following message which to me sug= gests that it's trying to validate against a dtd not the XML Schema. Document is invalid: no grammar found. Document root element "Book", must= match DOCTYPE root "null".=20 I'll keep digging about and see if I get anywhere. On Thu, 2003-02-06 at 17:40, Bonnet Emmanuel wrote: > Attached are the files I am using : > I guess you will have to change the access path for the schema location. >=20 > The message is "Document is invalid: no grammar found". >=20 > My code is : > String generated=3D"BookXsdGenerated.xml"; > Validator validator =3D new Validator(new FileReader(generated)); > this.assertTrue(validator.isValid()); >=20 > the pb occurs on the validator.isValid > -> parser triggers an exception. >=20 > I am wondering if it is not an access pb. > The SAME code is working properly with other > xml files with the same structure but which are > using a dtd validation. >=20 > Emmanuel >=20 >=20 > Jeff Martin a =C3=A9crit : >=20 > > I've never used XSD so I'm not sure what should happen, but the > > validator calls the parse method on the xml parser. Xerces2 is suppos= ed > > to support XSD validation and I assume that you just need to have a > > resolvable xmlns attribute in the root element and it should barf whe= n > > you try an parse the file. > > > > Can you give us an example? > > > > On Thu, 2003-02-06 at 16:36, Bonnet Emmanuel wrote: > > > Hi All, > > > I have trouble using the XmlUnit Validator with a > > > Xml file that must be validated with a XSD. > > > I use the following code > > > > > > Validator validator =3D new Validator(new FileReader(file)); > > > this.assertTrue(validator.isValid()); > > > > > > > > > And file contains the full reference to its XSD. > > > Do you have any idea about that ? > > > > > > Regards, > > > Emmanuel > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.NET email is sponsored by: > > > SourceForge Enterprise Edition + IBM + LinuxWorld =3D Something 2 S= ee! > > > http://www.vasoftware.com > > > _______________________________________________ > > > Xmlunit-general mailing list > > > Xml...@li... > > > https://lists.sourceforge.net/lists/listinfo/xmlunit-general > > -- > > Jeff Martin <je...@mk...> > > > > ------------------------------------------------------- > > This SF.NET email is sponsored by: > > SourceForge Enterprise Edition + IBM + LinuxWorld =3D Something 2 See= ! > > http://www.vasoftware.com > > _______________________________________________ > > Xmlunit-general mailing list > > Xml...@li... > > https://lists.sourceforge.net/lists/listinfo/xmlunit-general >=20 > -- >=20 > ------------------------------------------------------------------- > Emmanuel BONNET Mail : eb...@ge... > GENIGRAPH URL : http://www.genigraph.fr > Tertial II > 216, Route de St Simon Tel : +33 (0)5.34.60.92.84 > 31100 TOULOUSE - FRANCE Fax : +33 (0)5.34.60.92.89 > ------------------------------------------------------------------- >=20 >=20 > ______________________________________________________________________ >=20 > <?xml version=3D"1.0" encoding=3D"UTF-8"?> > <Book xmlns:xsd=3D"http://www.w3.org/2000/10/XMLSchema" xmlns=3D"http:/= /www.publishing.org" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instan= ce" xsi:schemaLocation=3D"http://www.publishing.org Book.xsd"> > <Title>Chicken Soup for the Soul</Title> > <Author>Jack Canfield</Author> > <Author>Mark Victor Hansen</Author> > <Date>1993</Date> > <ISBN>1-55874-262-X</ISBN> > <Publisher>Health Communications, Inc.</Publisher> > </Book> >=20 > ______________________________________________________________________ >=20 > <?xml version=3D"1.0"?> > <xsd:schema xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" > targetNamespace=3D"http://www.publishing.org" > xmlns=3D"http://www.publishing.org" > version=3D"1.0" > elementFormDefault=3D"qualified"> > =09 > <xsd:element name=3D"Book" type=3D"BookType"/> >=20 > <xsd:complexType name=3D"BookType"> > <xsd:sequence> > <xsd:element name=3D"Title" type=3D"xsd:string" minOccurs=3D= "1" maxOccurs=3D"1"/> > <xsd:element name=3D"Author" type=3D"xsd:string" minOccurs=3D= "1" maxOccurs=3D"unbounded"/> > <xsd:element name=3D"Date" type=3D"xsd:string" minOccurs=3D= "1" maxOccurs=3D"1"/> > <xsd:element name=3D"ISBN" type=3D"xsd:string" minOccurs=3D= "1" maxOccurs=3D"1"/> > <xsd:element name=3D"Publisher" type=3D"xsd:string" minOccu= rs=3D"1" maxOccurs=3D"1"/> > </xsd:sequence> > </xsd:complexType> > </xsd:schema> --=20 Jeff Martin <je...@mk...> |