Help with XML code

Started by
3 comments, last by shuma-gorath 10 years, 1 month ago

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>frames</key>
    </dict>
</plist>
        

So, I'm using pugixml, and untill now I was always able to extract the value of a node,but now there appears to be a problem:


pugi::xml_document doc;

doc.load_file("sprite_sheet.plist");

pugi::xml_node test = doc.child("plist").child("dict").child("key");

OutputDebugStringA(test.value());

There is no output. And I also used the debugger to check the values: test has the name "key", and NO value!

What is the problem?!

Advertisement

Have you tried TinyXML? If you are using it, this is how I parse data...


tinyxml2::XMLElement* root = doc.FirstChildElement();


while (root)
{
tinyxml2::XMLElement* child = root->FirstChildElement();
std::string name = child->Value();


if (name == "name")
{
}


root = NextSiblingElement();
}
Try using test.name() instead of test.value().

From the documentation:

Getting node data

Apart from structural information (parent, child nodes, attributes), nodes can have name and value, both of which are strings. Depending on node type, name or value may be absent. node_document nodes do not have a name or value, node_element and node_declaration nodes always have a name but never have a value, node_pcdata, node_cdata, node_comment and node_doctype nodes never have a name but always have a value (it may be empty though), node_pi nodes always have a name and a value (again, value may be empty). In order to get node's name or value, you can use the following functions:

const char_t* xml_node::name() const;
const char_t* xml_node::value() const;

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>frames</key>
    </dict>
</plist>
        

So, I'm using pugixml, and untill now I was always able to extract the value of a node,but now there appears to be a problem:


pugi::xml_document doc;

doc.load_file("sprite_sheet.plist");

pugi::xml_node test = doc.child("plist").child("dict").child("key");

OutputDebugStringA(test.value());

There is no output. And I also used the debugger to check the values: test has the name "key", and NO value!

What is the problem?!

You are trying to access inner text not a value of an XML node. Also have a look at tinyXML2 its easy to use

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

If memory serves me right, NightCreature83 is right. Use child_value() to get at the text nodes.

By the way, just so you know, pugixml tends to be faster than TinyXML, though I'm not sure if they sped up TinyXML2 that much.

This topic is closed to new replies.

Advertisement