• Advertisement
Sign in to follow this  

Help with XML code

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

If you intended to correct an error in the post then please contact us.

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;

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

Edited by noatom

Share this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
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 this post


Link to post
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;

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement