我想读一个特定的xml节点和它的价值,例如

<customers>
<name>John</name>
<lastname>fetcher</lastname>
</customer>

和我的代码后面应该有一些东西像这样(不知如何应寿:))

Response.Write(xml.Node["name"].Value) 

等等等。正如我所说这只是一个例子,因为我不知道如何做。所以你帮助我,请。

谢谢。

关于..

有帮助吗?

解决方案

最基本的答案:点击 假设 “XML” 是一个XMLDocument,XmlNodeList中,的XMLNode等...

Response.Write(xml.SelectSingleNode("//name").innerText)

其他提示

您使用的是哪个版本的.NET的?如果您使用.NET 3.5,并且可以使用LINQ到XML,它是那样简单:

document.Descendant("name").Value

(除了一些错误处理!)如果你STUK与DOM API,你可能想:

document.SelectSingleNode("//name").InnerText

请注意,这还没有表现出对你如何读取XML摆在首位什么 - 如果你需要的是一点帮助,请在问题给予更详细

如果使用早期版本的.净框架,看一看 如下 类第一,因为这是你怎么会加载XML string入。类似 XMLElementXMLNode 还有做一些这方面的工作。

还没有尝试测试它,但无论如何应该指向你在正确的方向

 'Create the XML Document
 Dim l_xmld As XmlDocument
'Create the XML Node
        Dim l_node As XmlNode

            l_xmld = New XmlDocument

            'Load the Xml file
            l_xmld.LoadXml("XML Filename as String")

            'get the attributes
            l_node = l_xmld.SelectSingleNode("/customers/name")

           Response.Write(l_node.InnerText)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top