2

I'm new in web service app using vbnet. the value return from service is in XML format.

<NewDataSet>
  <Table> 
    <Symbol>Fe</Symbol>
  </Table>
</NewDataSet>

How can I retrieve the value without writing it into text file. I know there's a namespace SYSTEM.XML but I'm not familiar with its classes :(

2
  • have you tried to read up on the subject? Is the problem with reading the xml or is your problem with storing it in a file? If it is the latter you might want to write it to a MemoryStream?
    – Chipmunk
    Apr 11, 2011 at 10:35
  • If you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it!
    – marc_s
    Apr 11, 2011 at 10:39

2 Answers 2

8

Let's assume that your web service call gives you that XML in a string.

Dim MyXml as String = YourWebService.GetXml()

If you want to get the value of the "Symbol" tag, you could do this...

Dim MyDoc as New System.Xml.XmlDocument
MyDoc.LoadXml(MyXml)
dim SymbolText as String = MyDoc.SelectSingleNode("//NewDataSet/Table/Symbol").InnerText

Hope this helps!

0
  Dim xmlstr As String = "<NewDataSet>
  <Table> 
    <Symbol>Fe</Symbol>
  </Table>
</NewDataSet>"
        Dim doc As XElement = XElement.Parse(xmlstr)

        For Each val As XElement In doc.Descendants("Table")

            If val.HasElements Then
                Dim Symbol As String = val.Element("Symbol").Value
            End If
        Next

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.