You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Nicolas Faillon <FA...@archimed.fr> on 2002/10/23 10:38:05 UTC

XML Schema

hello xml community!

I have got a problem with XML schema and the mailing list archives hadn't
help me.
I want to parse and validate the sample "personal-schema.xml" provided in
the distribution of xerces.

Here is my code:


	builderFactory = DocumentBuilderFactory.newInstance();
            
            builderFactory.setNamespaceAware(true);
            builderFactory.setValidating(true);
            
            builder = builderFactory.newDocumentBuilder();
            builder.setErrorHandler(new MyDefaultHandler());
            
            InputSource is = new InputSource(new
FileInputStream("C:/xerces-2_0_2/data/personal-schema.xml"));
            letter = builder.parse(is);



As you see, validation and namespace awareness are turn on.
"personal-schema.xml" can be validate against "personal.xsd" with XML tools
like XMLSpy

And here is my error output:

	org.xml.sax.SAXParseException: Document root element "personnel",
must match DOCTYPE root "null".
	at...

	org.xml.sax.SAXParseException: Document is invalid: no grammar
found.
	at...

I think the parser is trying to validate the xml file against a DTD instead
of a XML schema. Why?



I am currently working with xerces-J 2 and forte4J.



				nicolas, 
				france


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: XML Schema

Posted by Matthias Ferdinand <ma...@matthiasferdinand.de>.
Hi Nicolas,

you wrote:

> I want to parse and validate the sample "personal-schema.xml"
> provided in the distribution of xerces.

> I think the parser is trying to validate the xml file against a DTD
> instead of a XML schema. Why?

It may help to configure and execute the parser directly and switching
on explicitly the XML Schema validation like this (mentioned on
http://xml.apache.org/xerces2-j/features.html ):
-------------------------------------------------------------------------
parser = new DOMParser(); try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature( "http://apache.org/xml/features/validation/schema",
true); } catch ...

  try {
    parser.parse(xml_file);
    xml = parser.getDocument();
  }
  catch ...
-------------------------------------------------------------------------

Note that the root element of your XML file must contain a
reference to the schema file like this (more at
http://xml.apache.org/xerces2-j/faq-xs.html ):

<root
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xsi:noNamespaceSchemaLocation='personal.xsd'>


 Matthias                            

-- 
EMail: matthias@matthiasferdinand.de


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: XML Schema

Posted by Andy Clark <an...@apache.org>.
Nicolas Faillon wrote:
>             InputSource is = new InputSource(new
> FileInputStream("C:/xerces-2_0_2/data/personal-schema.xml"));

You should upgrade to Xerces 2.2.0. This may solve
the problems you're having.

-- 
Andy Clark * andyc@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org