Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help with XML code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 noatom   Members   -  Reputation: 782

Like
0Likes
Like

Posted 26 February 2014 - 11:22 AM

<?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, 26 February 2014 - 11:23 AM.


Sponsor:

#2 Irlan   Members   -  Reputation: 1494

Like
0Likes
Like

Posted 26 February 2014 - 12:41 PM

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


#3 TheComet   Members   -  Reputation: 1586

Like
0Likes
Like

Posted 26 February 2014 - 01:52 PM

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, 26 February 2014 - 01:56 PM.

YOUR_OPINION >/dev/null


#4 NightCreature83   Crossbones+   -  Reputation: 2825

Like
0Likes
Like

Posted 26 February 2014 - 02:44 PM

<?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, Mad Max

#5 shuma-gorath   Members   -  Reputation: 887

Like
0Likes
Like

Posted 27 February 2014 - 04:34 PM

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, 27 February 2014 - 04:37 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS