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 Orlando Ribeiro <or...@inescporto.pt> on 2001/05/04 17:33:47 UTC

Problem with Xerces DOMParser Validation

Hi,
      
      First of all thanks for helping me trying to resolve the problem
of the Xerces validation. I followed your instructions by trying to use
the “setFeature(…)” and reading more about the features on the Xerces
site  <http://xml.apache.org/xerces-j/features.html>
http://xml.apache.org/xerces-j/features.html, but the results were not
so good. I made the following modifications in my code:
 
      public org.w3c.dom.Document get_xerces_document (String
Xml_FileName)
       {      
DOMParser domParser = new DOMParser();          
       
              try
              {
domParser.setFeature("http://xml.org/sax/features/validation",true);
 
domParser.setFeature("http://apache.org/xml/features/validation/schema",
true);
 
domParser.setFeature("http://xml.org/sax/features/namespaces",true);
                     
              }catch (SAXNotRecognizedException e)
              {
                     System.err.println (e);
              } catch (SAXNotSupportedException e)
              {
                     System.err.println (e);
              }
 
              //Register Error Handler
              domParser.setErrorHandler (this);
 
try
              {      
domParser.parse( new InputSource( new FileInputStream( new
File(xml_FileName) ) ) );
 
              }catch(IOException ex) {
                     ex.printStackTrace();
              }catch(org.xml.sax.SAXException ex) {
                     ex.printStackTrace();
              }
              
              return domParser.getDocument();
       }
 
      
      The returned messages by the “Error Handler” were:
 
Error:  org.xml.sax.SAXParseException: Element type "orlando" must be
declared.
Error:  org.xml.sax.SAXParseException: Element type "name" must be
declared.
Error:  org.xml.sax.SAXParseException: Element type "surname" must be
declared.
Error:  org.xml.sax.SAXParseException: Element type "age" must be
declared.
 
The documents used for these were (one XML and the other is a Schema):
 
orlando.xsd:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
       <xsd:element name="orlando" type="Dados"/>
       <xsd:complexType name="Dados">
             <xsd:sequence>
                    <xsd:element name="name" type="xsd:string"/>
                    <xsd:element name=" surname" type="xsd:string"/>
                    <xsd:element name="age" type="xsd:integer"/>
             </xsd:sequence>
       </xsd:complexType>
</xsd:schema>
 
myExample.xml:
 
<?xml version="1.0" encoding="UTF-8"?>
<orlando xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\TEMP\orlando.xsd">
       <name>Orlando</name>
       <surname>Ribeiro</surname>
       <age>24</age>
</orlando>
 
 
I don’t understand the meaning of these messages since there is no
problem with the used document structure (the document is well-formed).
 
 
Am I doing something wrong or am I missing something? I can proceed with
the validation using a schema file, right?
One more time I ask for your help. Could anybody tell me what should I
do to make this work?
 
 
Thanks in advance,
Orlando Ribeiro
 

RE: Problem with Xerces DOMParser Validation

Posted by Inga Schuetz <sc...@darmstadt.gmd.de>.
Hello Orlando,

have you noticed that there is a space before surename in your schema. May
be this causes your problems.

Inga