我需要找回菁元素屬性使用在asp.net循環值XML節點的屬性值....在此先感謝如何檢索XML節點元素在asp.net
0
A
回答
0
依賴於.NET版本你使用。
的LINQ to XML是一條路可走:http://msdn.microsoft.com/en-us/library/bb387098.aspx
或者,如果你使用的是舊版本的.Net,XmlDocument的使用XPath是一條路可走:http://msdn.microsoft.com/en-us/library/ms256086(v=vs.80).aspx
0
對於.NET 2.0解決方案請參閱下面的例子:
我輸入文件名爲Books.xml和它的存儲INT我的樣本項目的Properties.Resources:
<?xml version="1.0" encoding="UTF-8" ?>
<books>
<book Title="Rage of angels" Author="Sidney Sheldon">Book 1</book>
<book Title="If tomorrow comes" Author="Sidney Sheldon">Book 2</book>
<book Title="Stranger in the mirror" Author="Sidney Sheldon">Book 3</book>
<book Title="A studyin scarlet" Author="Sir Arthur Conan Doyle">Book 4</book>
</books>
以下是處理xml文檔並將Title屬性的值寫入Visual Studio中的輸出窗口的實際代碼。簡單地修改代碼以滿足您的XML文件,你是好去:
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument document = new XmlDocument();
document.LoadXml(Properties.Resources.books.ToString());
ProcessXml(document,"/books/book", "book", "Title");
}
private void ProcessXml(XmlDocument document,string xPath,string elementName,string attributeName)
{
XmlElement root = document.DocumentElement;
XmlNodeList nodes = root.SelectNodes(xPath);
for (int i = 0; i < nodes.Count; i++)
{
string attribute = nodes[i].Attributes[attributeName].Value;
System.Diagnostics.Debug.WriteLine(attribute);
}
}
相關問題
- 1. 如何檢索XML節點,元素在asp.net
- 2. XSL - 如何檢索XML節點的基礎上的XML節點
- 3. 如何檢索xml節點的值?
- 4. ASP.NET C#搜索XML節點
- 5. 檢索Xml節點子元素作爲詞典
- 6. 通過使用Javascript或JQuery的元素值檢索XML節點
- 7. 檢索XML節點名稱
- 8. 從xml檢索節點值
- 9. LINQ XML子元素/節點
- 10. 刪除XML元素節點
- 11. 如何檢查AS3中某個節點的XML元素類型?
- 12. 如何檢測元素文本節點
- 13. 如何檢索asp.net中的xml元素屬性名稱
- 14. 如何使用Xpath檢索節點之後的XML樹節點?
- 15. C#XML元素計數的XML節點
- 16. 如何檢索XML嵌套的元素與C#的元素值
- 17. 如何同時檢索子節點和父節點XML節點的值?
- 18. 在Ruby和Hpricot中搜索元素的XML節點
- 19. 檢查xml元素是否存在(沒有子節點)
- 20. 如何使用xslt來計算xml元素中的xml節點
- 21. 如何在XML DOM節點樹中確定元素的結尾
- 22. 如何檢索元素
- 23. 如何在PHP中索引XML元素?
- 24. 檢索多個XML子節點值
- 25. 用xpath檢索xml節點值
- 26. 檢索特定的XML節點,jQuery
- 27. 檢索XML屬於特定節點
- 28. 的LINQ to XML檢索單個節點
- 29. jquery檢索頂級xml節點
- 30. 使用TSQL檢索XML節點值?
我使用.NET 2.O – user1225988 2012-02-23 06:58:35
我主要使用的.Net 2,我喜歡只使用XPath做的SelectNodes在XmlDocument上 – 2012-02-23 07:06:53