How to extract the value from a xml tag?
Below is the XML which is stored in a pointer variable response.
<Response>
<ID>App1</ID>
<operationID>654164615</operationID>
<mainReturnResult>
<returnCode>2000</returnCode>
<returnString> Success – Successful Result </returnString>
</mainReturnResult>
<totalDuration>647</totalDuration>
<Result>
<jobID>job1</jobID>
<mainReturnResult>
<returnCode>2000</returnCode>
<returnString> Success – Successful Result </returnString>
</mainReturnResult>
<duration>78</duration>
/*still more xml tags*/
-Data.to.be.taken
data comes here which have to extracted
-Done.with.data
I need only the return code and the data which is at the end of the xml.
I was using strstr to get the value of the tag return code. But when my friend seeing me doing that he said its a bad way to do it.
But, I need only the
1. return code to know the status and
2. to extract the data from the xml.
So, can you please suggest me which is the efficient way of doing these two activities without using any libraries.
Just parse it.
While I’ve written a lot of code for parsing stuff like this (mostly in C#), you can do something really simple here.
Just scan the text for
<returnCode>. The text you want starts after this. It ends at the next occurrence of</returnCode>. Easy.