[xsd-users] Handling XML data of unknown type

Raul Huertas raulh39 at tid.es
Mon Sep 4 07:25:33 EDT 2006


   Hi all,
   We are using version 2.7.0 of Xerces and version 2.2.0 of XSD and have
   noted that in the file
       xsd/cxx/xml/dom/elements.txx
   it is used the Xerces function
      DOMNode::getLocalName()
   For example, the line 25 reads:
        name_ (transcode<C> (e->getLocalName ())),
   with "e" being a xercesc::DOMElement wich derives from
   xercesc::DOMNode.
   The problem is that getLocalName() can return NULL. In fact, the
   Xerces documentation says:
   --------------
   virtual const XMLCh* DOMNode::getLocalName ( ) const [pure virtual]
   Returns the local part of the qualified name of this node.
   For nodes created with a DOM Level 1 method, such as createElement
   from the DOMDocument interface, it is null.
   Since:
    DOM Level 2
   --------------
   We are trying to use the second approach to handle XML data of an
   unknown type described in the XSD Wiki
   ([1]http://wiki.codesynthesis.com/Tree/FAQ), but it keeps failing in
   the validation code, throwing an exception:
       "unexpected element encountered"
   This are the relevant lines in our code:
       XercesDOMParser *parser = new XercesDOMParser; //Create the
   parser.
       parser->parse("peticion.xml");                 //Parse the file.
       DOMDocument * dom = parser->getDocument();     //Get the DOM
   document.

       DOMElement* rootElem = dom->getDocumentElement(); //Take rootElem
   to test which XML have the file
       // In this point rootElem->getTagName() returns a valid value:
   "Peticion", but
       // rootElem->getLocalName() returns NULL, so the next line...

       auto_ptr<EstadoSincronismoRequest> unaPeticion(Peticion(*dom));
       // ...throws the exception.
   (
   Our xsd have:
   <xsd:element name="Peticion" type="EstadoSincronismoRequest"/>
   )
   We think that it is not correct to use getLocalName(), but you have to
   use getTagName() or getNodeName(). Is it true?
   By the way, we have discovered that adding this line just before
   calling the parse method:
       parser->setDoNamespaces(true);
   makes the code work. !!
   Is this correct?
   (If this is correct, then I think that it should be pointed in he
   Wiki, shouldn't it?)
   Thanks.

References

   1. http://wiki.codesynthesis.com/Tree/FAQ



More information about the xsd-users mailing list