1

I have a function to load a xml file with TinyXML-2 library (v4.0.1). It always work fine, but today I see a problem that I don't know how to solve.

When I load de file:

if ( doc.LoadFile ( "file.xml" ) != tinyxml2::XML_SUCCESS )

It never return XML_SUCCESS. I'm watching many files and I see that only fail when the file has this line:

<?xml-stylesheet ...

Without this line it works fine. Why it's happening? What can I do for solve this problem?

Thanks.

Safej
  • 73
  • 10

1 Answers1

0

TinyXML2 does not support XML style sheets or document type definitions (DTDs) From the documentation:

TinyXML-2 doesn't parse or use DTDs (Document Type Definitions) or XSLs (eXtensible Stylesheet Language.)

That is why the XML read of the file with the <?xml-stylesheet ... definition is failing. Try commenting out this section. TinyXML2 observes the XML comment syntax of <!-- your comment -->

JimmyNJ
  • 1,134
  • 1
  • 8
  • 23
  • Thanks for your answer. This is what I did, delete the line before read with TinyXML-2 and now it works fine. I didn't know it doesn't read stylesheets. – Safej Apr 08 '17 at 22:12
  • Yes TinyXML2 is great library but fast and light for this reason. Apache Xerces supports document type definitions (DTDs) and other features - not sure about style sheets. You may want to check that out if you need more XML parsing options. – JimmyNJ Apr 09 '17 at 15:47