如果我在字符串中有一些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>"
谢谢,
答案 0 :(得分:0)
你可以使用Linq到xml,如下面的代码:
Dim xmlE As XElement = XElement.Parse(strXml)
Dim str As String = (From el In xmlE.Elements("customer").Elements("fname")
Select el.Value).Single()