Jump to content
  • Advertisement
Sign in to follow this  
medhassu

Problem in XML data retrieve

This topic is 4417 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

Hai Associates, I am working on Tinyxml parser since few days. I got one problem in retrieving the data from XML string as a text data by removing the XMl tags. Before this i posted a thresd on the same issue one of our member Mr.Grelle has given one solution. It is giving some problems. The following recursive function i am using. char *temp_buf[500]; int m=0; void Extract( ) { TiXmlDocument xdoc; xdoc.Parse(XMl string); RecurseTree(&xdoc); } void RecurseTree(TiXmlNode *pNode) { printf("%s\n", pNode->Value()); if((pNode->Value()!=NULL) && (pNode->Value()!="")) { temp_buf[m]=pNode->Value(); m++; } TiXmlNode *Child = pNode->FirstChild(); for(; Child; Child = pNode->IterateChildren(Child)) RecurseTree(Child); } This function i am using for following type of xmlstring <rx-event> <topic>Mgmt</topic> <subtopic>645268923afce</subtopic> <context>PubSubComm-3</context> <params> <rx-status>ok</rx-status> <column1>Hello</column1> <column2>412</column2> <column3>Welcome to</column3> <column4>India</column4> </params> </rx-event> Here for the first time i am calling this function retrieving 18 fields and for the second time i am calling this function for the same XMl string it is retrieving 36 fields(i.e double the existed fieds) third time tripling the fields. In next calls repeating the same fields. Sincere request don`t ask me to read tinyxml document.Give me some solution I am using C++ tinyxml parser.

Share this post


Link to post
Share on other sites
Advertisement
First of all I would use TiXmlHandle, that makes it a lot easy

TiXmlHandle(doc) handle;
pelem = handle.FirstChild("rx-event").FirstChild("topic").Element();
if(pelem != NULL)
{
//extract text of element here
}

//analog for all the other tags after rx-event

//now the param tags
//analog for column1, column2 .....
pelem = handle.FirstChild("rx-event").FirstChild.("params").FirstChild("rx-status").Element();
if(pelem != NULL)
{
//extract text of element here
}




You can also construct a handle from a TiXmlNode pointers

pNode = upperhandle.Child(....).Node()
TiXmlHandle handle(pNode);


Hope that helps
p.s.: there is a nice doxygen documentation about the library you should read that for more detailed information writing a xml parser is a matter of 10 minutes of work

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!