Hi,
Xerces doesn't modify your document; you should check the error handler
to see if the parsing was aborted because of an error. In this case the
returned DOM tree would be complete up to position of the error.
Alberto
Il 16/07/2012 10:25, neetha patil ha scritto:
Dear All,
I am using Xercesc_2_8 C++. I provide a XML file (containing an
invalid tag) to the
DOMBuilderparser. I then edit the DOM document which is generated and
save the document back to the XML file. The content of this file is
now truncated from the invalid tag onwards. Why does the parser modify
the file while parsing? How do I prevent the same? i.e., I want the
parser to report the error and continue parsing but not modify the XML
content.
Following is the snapshot of the XML file:-
...
...
<Header id="My Project Id" nameStructure="DevName" revision="0"
version="1">
...
</Header>
...
...
<Services>
...
...
</Services>
<!-- Invalid tag: No node name -->
<name="abc">
...
...
Following is the code snippet of the parser:-
*void CHelper::InitDOM()
*{
// m_pDomImpl is a pointer to DOMImplementation
m_pDomImpl = 0;
if(m_pDomImpl == NULL)
{
XMLPlatformUtils::Initialize();
m_pDomImpl =
DOMImplementationRegistry::getDOMImplementation( gLS );
}
}
*int CHelper::LoadFile(DOMBuilder** pParser, const CString&
strXMLFile, DOMDocument** pDoc, CStringArray& arrError, bool
bValidate, const CString& strSchemaFile)
*{
...
if(*pParser == NULL)
{
*pParser =
((DOMImplementationLS*)m_pDomImpl)->createDOMBuilder
(DOMImplementationLS::MODE_SYNCHRONOUS,
0 );
if((*pParser) ==NULL)
{
return DOM_INITIALIZE_FAILED;
}
(*pParser)->setFeature( XMLUni::fgDOMNamespaces, true );
(*pParser)->setFeature( XMLUni::fgXercesSchema, true );
(*pParser)->setFeature(
XMLUni::fgXercesSchemaFullChecking, true );
(*pParser)->setFeature( XMLUni::fgDOMValidation, true);
(*pParser)->setFeature(
XMLUni::fgXercesCacheGrammarFromParse, true);
}
try
{
CMyDOMErrHandler eh();
m_arrValidationErrs.RemoveAll();
// parseURI a blocking call. All the errors will be
reported first if any error handler is set
// then only the next line will be executed.
if(bValidate == true)
{
(*pParser)->setErrorHandler(&eh);
(*pParser)->loadGrammar( strSchemaFile,
Grammar::SchemaGrammarType, true);
}
else
{
(*pParser)->setErrorHandler(NULL);
}
*pDoc =(*pParser)->parseURI(strXMLFile);
...
...
}
catch(...)
{
...
}
return SUCCESS;
}
Thank you in advance.
Regards,
Neetha