xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Pelton <...@PKC.com>
Subject RE: Re: Validation documents with SAX in C++
Date Mon, 12 Sep 2011 12:21:52 GMT
The error is in your XML.  If you use the schemaLocation attribute, its value must consist
of namespace and schema location pairs separated by spaces.  To specify just a location use
the noNamespaceSchemaLocation attribute instead of the schemaLocation attribute.

-----Original Message-----
From: alessandra.brindisi@virgilio.it [mailto:alessandra.brindisi@virgilio.it] 
Sent: Monday, September 12, 2011 8:08 AM
To: c-users@xerces.apache.org
Subject: R: Re: Validation documents with SAX in C++

I implemented the following algorithm:

int main(int argC, char* argV[])

        char* filename;
        bool dtdValidate = false;
        bool xsdValidate = false;
        char* schemaSorgente;
        char* dtdSorgente;
        int i;

        catch (const XMLException&amp; toCatch)
         XERCES_STD_QUALIFIER cerr << "Si รจ verificato un errore in fase di inizializzazione!
              << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
         return 1;

        for (i = 1; i < argC; i++) {
          if (!strcmp(argV[i], "-dtd")) {
                dtdValidate = true;
                dtdSorgente = argV[++i];
            } else if (!strcmp(argV[i], "-xsd")) {
                xsdValidate = true;
                 schemaSorgente = argV[++i];


    xmlFile = argV[3];
     int errorCount = 0;

    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);

    int errorCode = 0;
       XmlToTestoSAX handler(encodingName, unRepFlags);
      //  parser->setDocumentHandler(&amp;handler);

        errorCount = parser->getErrorCount();

    catch (const OutOfMemoryException&amp;)
        XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER
        errorCode = 5;
    catch (const XMLException&amp; toCatch)
        XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n  Error: "
             << StrX(toCatch.getMessage())
             << "\n" << XERCES_STD_QUALIFIER endl;
        errorCode = 4;
    if(errorCode) {
        return errorCode;

    //  Delete the parser itself.  Must be done prior to calling Terminate, below.
    delete parser;

    // And call the termination method

    if (errorCount > 0)
        return 4;
        return 0;

but I believe there are errors. Pass the following parameters from the command line:

-xsd xml\personal.xsd xml\personal-schema.xml
The xml file input is given in the following:

<?xml version="1.0" encoding="UTF-8"?>
<?proc-inst-1 'foo' ?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="C:/Documents and Settings/Alessandra/Documenti/Visual Studio 2008/Projects/XmlToTestoSAXMain/xml/personal.xsd"

  <person id="Big.Boss">
    <name xml:base="foo/bar"><family  xml:base="bar/bar">Boss</family> <given
xml:base="car/bar">Big</given><?proc-inst-2 'foobar' ?></name>
    <link subordinates="one.worker two.worker three.worker four.worker five.worker"/>

  <person id="one.worker" xml:base="/auto/bar">
    <name xml:base="/car/foo/"><family xml:base="bar/bar">Worker</family>
    <link manager="Big.Boss"/>
XSD schema is:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>

 <xs:import namespace="http://www.w3.org/XML/1998/namespace">
        The schemaLocation of the relevant file is
        "http://www.w3.org/2001/xml.xsd"; however,
        we don't want to assume people are always
        connected to the 'net when playing with this file.

 <xs:element name="personnel">
     <xs:element ref="person" minOccurs='1' maxOccurs='unbounded'/>

  <xs:unique name="unique1">
   <xs:selector xpath="person"/>
   <xs:field xpath="name/given"/>
   <xs:field xpath="name/family"/>
  <xs:key name='empid'>
   <xs:selector xpath="person"/>
   <xs:field xpath="@id"/>
  <xs:keyref name="keyref1" refer='empid'>
   <xs:selector xpath="person"/> 
   <xs:field xpath="link/@manager"/>  


 <xs:element name="person">
     <xs:element ref="name"/>
     <xs:element ref="email" minOccurs='0' maxOccurs='unbounded'/>
     <xs:element ref="url"   minOccurs='0' maxOccurs='unbounded'/>
     <xs:element ref="link"  minOccurs='0' maxOccurs='1'/>
   <xs:attribute name="id"  type="xs:ID" use='required'/>
   <xs:attribute name="note" type="xs:string"/>
   <xs:attribute name="contr" default="false">
     <xs:restriction base = "xs:string">
       <xs:enumeration value="true"/>
       <xs:enumeration value="false"/>
   <xs:attribute name="salary" type="xs:integer"/>
   <xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>

 <xs:element name="name">
    <xs:element ref="family"/>
    <xs:element ref="given"/>
   <xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>

 <xs:element name="family">
       <xs:extension base='xs:string'>
          <xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>

 <xs:element name="given" >
       <xs:extension base='xs:string'>
          <xs:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="skip"/>

 <xs:element name="email" type='xs:string'/>

 <xs:element name="url">
   <xs:attribute name="href" type="xs:string" default="http://"/>

 <xs:element name="link">
   <xs:attribute name="manager" type="xs:IDREF"/>
   <xs:attribute name="subordinates" type="xs:IDREFS"/>

 <xs:notation name='gif' public='-//APP/Photoshop/4.0' system='photoshop.exe'/>


 When you launch the program running I get the following screen:

Fatal error at file C:\Documents and Settings\Alessandra\Documenti\Visual Studio 2008\Projects\XmlToTestoSAXMain\xml\personal-schema.xml,
line 6, char 6
Message: schemaLocation does not contain name-space location pairs

There are errors in the file. Xml or. Xsd? Furthermore, my algorithm allows to validate an
XML document based on a DTD or XSD supplied from the outside? Thank you. greetings

----Messaggio originale----
Da: marl@mebius.net
Data: 9-set-2011 8.20
A: <c-users@xerces.apache.org>
Ogg: Re: Validation documents with SAX in C++

alessandra.brindisi@virgilio.it wrote:
>   Hello, you can have some indication of the methods used to check whether an XML document
conforms to a DTD or XSD with SAX in C++.
> Thank you. Alessandra greetings.


Please look at the SAX2Count sample source code from the Xerces-C++
source distribution.

Good luck!

View raw message