Parse string with xml data in vb.net

Dear All,

I am completely new to XML, and I would appreciate if you help me with the code in VB.NET to parse the string in the attachment containing XML data to get the values of the elements “f:cn” and “e:attachment”.

Please find the attachment containing the xml data. I neeed to pass it as a streing and not as a xml file.

I am in a pressing deadline to deliver, will really appreciate if you help me out.

DOMDocument.loadXML()

Is the method you can use to load the XML string.

In regards to those elements, they exist on a namespace that I think you will have to register with the parser.

i use the loadxml method and also preserviing whitepsace.

after that how do i retreieve the values of nodes “f:cn” and “e:attachmentfile”??

Dim XMLDoc As New XmlDocument()

XMLDoc.LoadXML(string)

Dim nodeList As XmlNodeList = XMLDoc.GetElementsByTagName(“f:cn”)
Dim i As Integer

For i = 0 To nodeList.Count - 1
Console.WriteLine(nodeList(i).nodeName)
Next i

If the above doesn’t work, try looking into this:
http://samples.gotdotnet.com/quickstart/howto/doc/Xml/XmlNameSpace.aspx

i tried the code given by you.

it displays the name of the node “f:cn” but not the value of the “f:cn” node.

also how can i modify the code to include the node"e:attachmentfilename"

thanks so much

Change GetElementsByTagName(“f:cn”) to

GetElementsByTagName(“e:attachmentfilename”)

To get the contents try:

For i = 0 To nodeList.Count - 1
Console.WriteLine(nodeList(i).innerXML)
Next i

can you combine these two getelementtagnanmes into one for loop?

From the example you gave there’s no point in using a loop.

Try:
Console.WriteLine("f:cn Value: " + XMLDoc.GetElementsByTagName(“f:cn”).item(0).innerXML)

Console.WriteLine("e:attachmentfilename Value: " + XMLDoc.GetElementsByTagName(“e:attachmentfilename”).item(0).innerXML)