Hello there,

We recently upgraded our libraries from Xerces C++ 1.7.0 to Xerces C++
2.5.0. We upgraded our C++ code to comply with the new Xerces C++ parser.
However, we are still trying to resolve an issue with compiling the VXML
files against a DTD in memory. We are using the XercesDOMParser  object. Our
VXML files don't include a DOCTYPE line, we rely on the in-memory DTD
grammar for parsing the VXML files.

NOTE: our DTD file does not contain explicit ENTITY references, just ELEMENT
and ATTLIST entries.

Prior to the upgrade, our code looked like the one shown below for loading
and parsing the DTD, and then parsing the VXML files:

OLD CODE (compliant with Xerces 1.7.0)
--------

DOMParser VxmlParser;
std::string inputdtd; <---- contains the DTD text
. . .
parser::parser(void)
{
    . . .
    // Turn the Voice XML grammar DTD into a memory buffer input source
    const XMLByte* dtdsource =
        reinterpret_cast<const XMLByte*>(inputdtd.c_str());
    // Create DTD input source
    MemBufInputSource dtdsrc(dtdsource, inputdtd.length(), "VoiceXML");

    // Initialize the DOM parsing object to reuse the VXML grammar DTD
    VxmlParser.setValidationScheme(DOMParser::Val_Always);
    VxmlParser.setErrorHandler(this);

    // Load the VXML grammar DTD. Our DTD is an internal subset
    VxmlParser.parse(dtdsrc);

void vxmlparser::parse(const char* filename)
{
    VxmlParser.reset();
    // parse the given VXML file, reusing the VXML grammar DTD
    VxmlParser.parse(filename, true);
    . . .
}

After the upgrade to Xerces 2.5.0, following is our attempt to migrate the
parse code. However, the VxmlParser->parse() call will not parse the VXML
file against the DTD in memory. The loadGrammar() method does load the DTD
grammar and pre-parses it, but it is not used afterwards. The only way for
xmlParser->parse() call to succeed is to include the DOCTYPE external
reference entry in the file (See examples below).

Can anyone shed some light on what's missing/incorrect in the code below?


NEW CODE
--------

XercesDOMParser *VxmlParser;
std::string inputdtd;
. . .
// constructor - loads the VXML grammar DTD
Vxmlparser::vxmlparser(void)
{
    . . .
    // Turn the Voice XML grammar DTD into a memory buffer input source
    const XMLByte* dtdsource =
        reinterpret_cast<const XMLByte*>(inputdtd.c_str());
    // Create DTD input source
    MemBufInputSource dtdsrc(dtdsource, inputdtd.length(), "VoiceXML");

    // Initialize the DOM parsing object to reuse the VXML grammar DTD
    VxmlParser = new XercesDOMParser();
    VxmlParser->setValidationScheme(XercesDOMParser::Val_Always);

    VxmlParser->setErrorHandler(this);

    VxmlParser->cacheGrammarFromParse(true); // may be redundant
    // Load VXML DTD grammar and cache it for re-use
    VxmlParser->loadGrammar(dtdsrc, Grammar::DTDGrammarType, true);
    VxmlParser->useCachedGrammarInParse(true);
}

// Method to parse the VXML files against VXML grammar DTD
vxmlparser::parse(const char* filename)
{

  VxmlParser->resetDocumentPool();
  VxmlParser->parse(filename);
  VxmlParser->resetCachedGrammarPool();

--------------------------------------------------

Sample DTD file (person.dtd):
----------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!ELEMENT name (#PCDATA)>
<!ELEMENT person (name)>

Sample XML file that doesn't work:
---------------------------------
<?xml version="1.0"?>
<person>
<name>patrick</name>
</person>

Compiler returns this error:
Error (parsing can continue) at file person.grxml, line 4, char 6 --
Message: Unknown element 'name'



Sample XML file that works (with explicit DOCTYPE reference):
------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE person SYSTEM "person.dtd">
<person>
<name>patrick</name>
</person>



Thanks!!

--Carolina


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to