2015-06-19 60 views
1

我使用XmlDocument類是這樣的:XmlDocument.SelectSingleNode使用什麼版本的XPath?

divisionsDoc.SelectSingleNode(
    string.Format(@"Root/PoliticalDivisions/PoliticalDivision[upper-case(@Code)='{0}']", withCode.ToUpper())); 

,這是導致錯誤:

Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

我推測這是由於upper-case XPath函數,這是我理解存在XPath 2.0而不是1.0(從here,here等)

MSDN不指定它使用的XPath的版本。我將.NET 4.5.1作爲目標 - 不會遲到使用XPath 2.0嗎?還是那些在.NET以外定義的東西?

我怎樣才能知道XPath的目標版本?

請注意,我知道使用translate('some text','abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')的解決方法 - 這不是我要求的。

+2

另外,您是否需要*在這裏使用XPath?我個人只是使​​用LINQ to XML - 例如,不需要擔心'withCode'是否包含撇號 - 但是我很感謝你可能有其他要求。 –

+0

[基本查詢Linq to XML](https://msdn.microsoft.com/en-us/library/bb943906.aspx) – MethodMan

+0

否... Microsoft從未實施過XPath 2.0或Xslt 2.0。請參閱2011年的http://stackoverflow.com/a/7521282/613130.在一條評論中,有人要求在2014年進行更新...... – xanatos

回答

5

微軟從來沒有實現過的XPath 2.0或XSLT 2.0 ...例如見這個uservoice的2013(恰當地命名爲本地XPath的2.0或.NET支持XSLT 2.0)...

去年三月的評論2015 by one user:

i guess we will never see this as the world doesn't like XML anymore, it's all about JSON. Which is a shame as XML is still far better for a number of key scenarios than JSON.