1

如果我在字符串中有一些 xml,我该如何阅读并挑选出每个元素的值?什么是最快最简单的方法?

    Dim strXml As String = "<subscription>"
    strXml = strXml & "<reference>abc123</reference>"
    strXml = strXml & "<status>active</status>"
    strXml = strXml & "<customer>"
    strXml = strXml & "<fname>Joe</fname>"
    strXml = strXml & "<lname>bloggs</lname>"
    strXml = strXml & "<company>Bloggs inc</company>"
    strXml = strXml & "<phone>1234567890</phone>"
    strXml = strXml & "<email>joebloggs@hotmail.com</email>"
    strXml = strXml & "</customer>"
    strXml = strXml & "</subscription>"

谢谢,

4

1 回答 1

0

您可以使用 Linq to xml,如下代码:

    Dim xmlE As XElement = XElement.Parse(strXml)

    Dim str As String = (From el In xmlE.Elements("customer").Elements("fname")
                        Select el.Value).Single()
于 2012-06-17T12:38:26.450 回答