2010-11-26 42 views
2

我在iPhone上使用GDataXML(在後臺使用libxml2)從XML文件讀取名稱列表。GDataXML/Libxml2 XPath concat不起作用

<persons> 
    <person id=1> 
     <firstname>John<firstname> 
     <lastname>Doe<lastname> 
    </person> 
</persons> 

但是,當我嘗試Concat的第一和姓氏與

/persons/person/concat(firstname, ' ', lastname) 

它不與GDataXML工作。當用.NET XML庫創建示例時,或者使用AquaPath對其進行測試時,它就可以工作。

任何提示或其他選擇讓它工作?

+0

問得好,+1。請參閱我的答案以獲得解釋和完整解決方案。 :) – 2010-11-26 19:03:05

+0

[AquaPath](http://ditchnet.org/aquapath/)是一個XPath 2.0評估程序。 – 2010-11-26 19:18:57

回答

1

But when i try to concat first and lastname with

/persons/person/concat(firstname, ' ', lastname) 

it doesn't work with GDataXML.

的libxml僅執行的XPath 1.0

上述表達式在XPath 1.0中不是語法上正確的(這是正確的XPath 2.0表達式)。

When trying the same with example with the .NET XML libary or testing it with AquaPath it works.

你弄錯了有關.NET XML(除非您使用的是第三方的XPath 2.0處理器如薩克森,Altova公司或XQSharp) - .NET未實現的XPath 2.0

解決方案

使用以下XPath 1.0表達式:

concat(/*/*/firstname, ' ', /*/*/lastname)