Question

I have an xml file that looks like the following

<siteinfo>
...
</siteinfo>
<page>
   <title>...</title>
   <revision>
   ...
   <revision>
</page>

It does not have a root/enclosing node so I get the "extra content at end of document" on running my program. After opening the file for parsing using libxml, is there a way to easily add this root/enclosing node to the parse tree?

Was it helpful?

Solution

If you can't change the structure of the source XML, an easier way would be to create a string like:

string xml = string("<root>") + file_contents + string("</root>");

Then you can parse this string easily. By the way, since you're using C++, you should give libxml++ a try. It is a C++ wrapper for libxml and it is very good.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top