Skip to content

Parsing XML string... Please help.. :)

Bob Boursaw

Asked Oct 15, 2005, 1:31 PM EDT2 answers
Share
LinkedInX
Hey everyone,

I'm sure this is probably very basic but I could sure use some help.

I have a very small XML string which comes in to my application via an event.

I want to parse out the information from this string and store the bits of information in to variables.

The xml string is
<MSG><CMD>DATA</CMD><MEDIA>1</MEDIA><TASK>5680</TASK><ANI/><DNIS>6940</DNIS><DATA1>1111111</DATA1><DATA2/><DATA3/><DATA4/><DATA5/></MSG>

All I am trying to do right now is parse out the data within the DATA1 tags.

Any help would be greatly appreciated.

Thanks,
Bob

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    int beginIndex = message.IndexOf("<Data1>") + 7; //gets index of the character after the >.
    int endIndex = message.IndexOf("</Data1>"); //gets the index of the character just after the end of your data.

    string myData = message.Substring(beginIndex, endIndex-beginIndex);
    0
  • 0
    Ok,

    I'm missing something here.

    I understand the code you provided but how do you specify where the <DATA1> tag resides? 

    In a file out on disk, defined within a text string called inboundXML, etc?

    In my case, I have a long XML string stored in a variable called inboundXML.  How do I tell it to look within this string?
    0