HOW TO:使用 Visual C# .NET 通過 XPath 表達(dá)式查詢 XML
本文的發(fā)布號曾為 CHS308333
概要本文演示如何使用 XPathNavigator 類通過 XML 路徑語言 (XPath) 表達(dá)式查詢 XPathDocument 對象。XPath 用于以編程方式計(jì)算表達(dá)式并選擇文檔中的特定節(jié)點(diǎn)。
要求下面的列表列出了推薦使用的硬件、軟件、網(wǎng)絡(luò)基礎(chǔ)結(jié)構(gòu)以及所需的服務(wù)包:
如何用 XPath 表達(dá)式查詢 XML
疑難解答在測試代碼時(shí),您可能會(huì)收到以下異常錯(cuò)誤信息:An unhandled exception of type ‘System.Xml.XmlException‘ occurred in System.xml.dll
該異常錯(cuò)誤發(fā)生在以下代碼行上: Additional information:System error.
該異常錯(cuò)誤是由無效的處理指令導(dǎo)致的。例如,處理指令可能包含多余的空格。下面是無效處理指令的示例:
若要解決該異常,請執(zhí)行以下操作之一:
參考下列文件可從 Microsoft 下載中心下載:
有關(guān)更多信息,請?jiān)L問以下 Microsoft Web 站點(diǎn): .NET 中的 XML:.NET Framework XML Classes and C# Offer Simple, Scalable Data Manipulation(.NET 中的 XML:.NET 框架 XML 類和 C# 提供簡單的可縮放的數(shù)據(jù)操作)R/> http://msdn.microsoft.com/msdnmag/issues/01/01/xml/default.aspx (http://msdn.microsoft.com/msdnmag/issues/01/01/xml/default.aspx)
有關(guān) XPath 的更多信息,請?jiān)L問下列 WWW 聯(lián)合會(huì) (W3C) Web 站點(diǎn):
XPathNavigator Class http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorClassTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorClassTopic.asp) XPathDocument Class(XPathDocument 類) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathDocumentClassTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathDocumentClassTopic.asp) XPathNodeIterator Class(XPathNodeIterator 類) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNodeIteratorClassTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNodeIteratorClassTopic.asp) XSLT Transformations with the XslTransform Class(使用 XslTransform 類 的 XSLT 轉(zhuǎn)換) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconxslttransformationswithxsltransformclass.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconxslttransformationswithxsltransformclass.asp) XPath Examples(XPath 示例) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefxpathexamples.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefxpathexamples.asp) XPath Syntax(XPath 語法) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefxpathsyntax.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefxpathsyntax.asp) XML 路徑語言 (XPath)
1.0 版:W3C 在 1999 年 11 月 16 日提出的建議 http://www./TR/1999/REC-xpath-19991116 (http://www./TR/1999/REC-xpath-19991116) |
|