0

I've the following XML:

<?xml version="1.0" encoding="utf-8"?>
<jack>
    <client name="Music Player Daemon">
        <port name="left">
            <connection port="jamin:in_L" />
        </port>
        <port name="right">
            <connection port="jamin:in_R" />
        </port>
    </client>
</jack>

I'm trying to parse it using PugiXML but after load my document is empty, the result description say no error:

pugi::xml_document doc;
pugi::xml_parse_result result = doc.load("/location/filename.xml");
std::cout << "Load result: " << result.description() << std::endl;

but it's a empty doc:

std::size_t numitens = std::distance(doc.begin(), doc.end());
std::cout << numitens << std::endl;

Output:

Load result: No error
0

I think that XML isn't problem, right ?

The XML is generated by other app, so I can't change, if have a problem in XML I'll need change XML parser ? TinyXML or libxml++ ?

Victor Aurélio
  • 2,355
  • 2
  • 24
  • 48

1 Answers1

1

doc.load() loads the string, not the file. You have to use doc.load_file().

Ideally the parsing of the string "/location/filename.xml" should've failed; there are complicated reasons why it does not, mostly related to backwards compatibility.

zeuxcg
  • 9,216
  • 1
  • 26
  • 33
  • thanks, now xml is loaded successfully, I can doc.child("jack"); but doc.root() isn't 'jack' why ? – Victor Aurélio Jun 27 '13 at 15:35
  • 1
    doc.root() is synonymous with doc; the member is actually that of xml_node, so it's not intended for use in xml_document. You're looking for doc.document_element(). – zeuxcg Jun 27 '13 at 16:00