Sign in to follow this  

Problem in XML data retrieve

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

This topic is 4200 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this