开发者

get value from XML in vbnet

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 :(


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!


  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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜