Help with XML code

This topic is 2055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

<?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;

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?!

Edited by noatom

Share on other sites

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();
}

Share on other sites
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_pcdatanode_cdatanode_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;

Edited by TheComet

Share on other sites
<?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;

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

Share on other sites

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.

Edited by shuma-gorath

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22