You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by vivekanand <vi...@gmail.com> on 2010/05/10 13:37:03 UTC

loadGrammer function fails when two DOMLSInput XSDs are loaded.

I have an XML(ipo.xml) which need to be validated against two XSD's (ipo.xsd
and address.xsd). I found relevant code in following link:
http://www.codesynthesis.com/~boris/blog/2010/03/15/validating-external-schemas-xerces-cxx/
and file load-grammar-dom.cxx.
and i obtain following out put:
loading address.xsd
loading ipo.xsd
:0:0 warning: unable to open primary document entity '/asd/address.xsd'
parsing ipo.xml


But my requirement is bit different. I get this XDS's as vector of
std::string rather than a files.
and i am using DOMLSInput to load it to loadGrammar function.I find that
Xerces behaves differently :(
I won't get any load errors but the grammer for the second file is not
loaded :( 
and corresponding errors( so and so element is not defined) are shown when
XML is parsed. i obtain following out put:
loading XSD
loading XSD
parsing ipo.xml
ipo.xml:5:26 error: no declaration found for element 'ipo:purchaseOrder'
ipo.xml:5:26 error: attribute 'orderDate' is not declared for element
'ipo:purchaseOrder'



here is the code snipet: 
int validateXML(vector & xsdStr, string & xmlStr)
{
  int r (0);
  XMLPlatformUtils::Initialize ();
  while (true)
  {
    MemoryManager* mm (XMLPlatformUtils::fgMemoryManager);
    auto_ptr gp (new XMLGrammarPoolImpl (mm));

    int i (1);

    // Load the schemas into grammar pool.
    //
    {
      DOMLSParser* parser (create_parser (gp.get ()));

      error_handler eh;
      parser->getDomConfig ()->setParameter (XMLUni::fgDOMErrorHandler,
&eh);
        char outfile[20];

      DOMLSInput* input = ((DOMImplementationLS*)impl)->createLSInput();
      for (vector::iterator it=xsdStr.begin(); it < xsdStr.end(); it++)
      {
        if(it->empty())
                continue;
        cerr << "loading XSD " << endl;
        input->setStringData(XMLString::transcode(it->c_str()));
        input->setEncoding(XMLUni::fgXMLChEncodingString);
        //if (!parser->loadGrammar (it->c_str (),
Grammar::SchemaGrammarType, true))
        if (!parser->loadGrammar (input, Grammar::SchemaGrammarType, true))
        {
          cerr << ": error: unable to load" << endl;
          r = 1;
          break;
        }

        if (eh.failed ())
        {
          r = 1;
          break;
        }
                snprintf(outfile,20,"outfile%d.txt",i);
                BinOutputStream* outStream = new
BinFileOutputStream(outfile);
        gp->serializeGrammars(outStream);
      }

      parser->release ();

      if (r != 0)
        break;
    }

    // Lock the grammar pool. This is necessary if we plan to use the
    // same grammar pool in multiple threads (this way we can reuse the
    // same grammar in multiple parsers). Locking the pool disallows any
    // modifications to the pool, such as an attempt by one of the threads
    // to cache additional schemas.

    gp->lockPool ();

    // Parse the XML documents.
    //
    DOMLSParser* parser (create_parser (gp.get ()));

    error_handler eh;
    parser->getDomConfig ()->setParameter (XMLUni::fgDOMErrorHandler, &eh);

//    for (; i < argc; ++i)
    {
      cerr << "parsing " << xmlStr.c_str() << endl;
      DOMDocument* doc (parser->parseURI (xmlStr.c_str()));

      if (doc)
        doc->release ();

      if (eh.failed ())
      {
        r = 1;
//        break;
      }
    }

    parser->release ();
    break;
  }

  XMLPlatformUtils::Terminate ();

  return r;
}
you can find the rest of code in the link mentioned above..
i am attaching the XML and XSD with this mail..

is this a bug in Xerces?? or am i doing some thing wrong while loading  the
XSD??
Appreciate any help or suggestions on this ...
http://old.nabble.com/file/p28510470/ipo.xml ipo.xml 
http://old.nabble.com/file/p28510470/ipo.xsd ipo.xsd 
http://old.nabble.com/file/p28510470/address.xsd address.xsd 
-- 
View this message in context: http://old.nabble.com/loadGrammer-function-fails-when-two-DOMLSInput-XSDs-are-loaded.-tp28510470p28510470.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.