读取XML节点
问题描述:
我想读一个特定的XML节点,它是例如读取XML节点
<customers>
<name>John</name>
<lastname>fetcher</lastname>
</customer>
价值,我后面的代码应该是这样的一些东西(我不知道应该如何寿:))
Response.Write(xml.Node["name"].Value)
等等等等。正如我所说这只是一个例子因为我不知道该怎么做。所以请你帮助我。
谢谢。
Regards ..
答
最基本的答案:
假设 “XML” 是一个XMLDocument,XmlNodeList中,的XMLNode等..
Response.Write(xml.SelectSingleNode("//name").innerText)
答
您正在使用哪个版本的.NET?
document.Descendant("name").Value
(!除了一些错误处理)如果你STUK与DOM API,你可能想:如果您在使用.NET 3.5,并且可以使用LINQ到XML,它是那样简单
document.SelectSingleNode("//name").InnerText
请注意,这并没有说明你如何阅读XML - 如果你需要关于这一点的帮助,请给出更详细的问题。
答
还没有尝试过测试,但应该指向你在正确的方向反正
'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)
谢谢,其实你的建议是足以让我现在:) – Tarik 2008-12-11 17:59:24