1

I have found some fantastic examples of how to use boost property trees to read xml files. However, the real head scratcher for me is extracting the DOCTYPE value. Given an xml file with the line:

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

If I do something like this:

// Create an empty property tree object
boost::property_tree::ptree pt;

// Load the XML file into the property tree.
boost::property_tree::read_xml(filenameIn, pt);

// and then immediately write it back out again...
boost::property_tree::write_xml(filenameOut, pt);

I would expect content(filenameOut) == content(filenameIn).

But this isn't the case. Specifically the DOCTYPE node is missing. Therefore how can I extract the value of the DOCTYPE node?

Ben J
  • 1,367
  • 2
  • 15
  • 33

1 Answers1

3

You can't.

PropertyTree is a library for serializing/deserializing trees of properties, to a number of formats that might be easy to consume elsehwere.

PropertyTree is not an XML library. Or a JSON library.

About adding the processing instruction: you can use an undocumented part of the API:

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Right, but boost property tree does have an xml_parser which uses rapidxml as its underlying implementation. And as far as I can tell, rapidxml does allow parsing a doctype node. But from digging through the boost code, it seems that boost doesn't take advantage of it. – Ben J Apr 21 '15 at 15:03
  • Boost does take advantage of it. To implement Property Trees. What did you expect? – sehe Apr 21 '15 at 15:10
  • _(What's stopping you from using rapidxml if an XML library is what you need? Seems such a detour to force everything into a poperty tree first)_ – sehe Apr 21 '15 at 15:11
  • If I've understood the code base correctly (quite unlikely ;-) ), the rapidxml flag 'parse_doctype_node' isn't supported by boost property trees. Thus when an xml file containing a doctype node is parsed, the doctype node is simply ignored. – Ben J Apr 21 '15 at 15:11
  • Using rapidxml directly seems like a sensible idea :-) – Ben J Apr 21 '15 at 15:12
  • @BenJ Of course it ignores it. Because it has no relevance to Property Tree. – sehe Apr 21 '15 at 15:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75839/discussion-between-sehe-and-ben-j). – sehe Apr 21 '15 at 15:14