2010-11-26 7 views
2

私はXMLファイルから名前のリストを読むためにiPhone上でGDataXML(バックグラウンドでlibxml2を使用しています)を使用しています。GDataXML/Libxml2 XPath連結が機能しません

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

しかし、私は

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

で最初と姓CONCATしようとすると、それはGDataXMLでは動作しません。 .NET XMLライブラリを使用して同じことを試したり、AquaPathでテストしたりするときにはうまくいきます。

ヒントやその他の選択肢がありますか?

+0

良い質問、1:

次のXPath 1.0式を使用してください。説明と完全な解決策については私の答えを見てください。 :) –

+0

[AquaPath](http://ditchnet.org/aquapath/)は、XPath 2.0の評価ツールです。 –

答えて

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式です)。 (あなたは、このようなサクソン、AltovaのかXQSharpなどのサードパーティのXPath 2.0プロセッサを使用していない限り)

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

あなたは、.NET XMLについて間違っている - .NETは、XPath 2.0を実装していません。

ソリューション

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

@Dimitre:この場合でも、空白のテキストノードのみを保存するXMLツリープロバイダでは、 'normalize-space(/ persons/person [1])'が機能します。 –

+0

@Dimitrie:私のためには機能しません... AquaPathやChrome XML拡張でも動作しません...私はいつも 'エラー:INVALID_EXPRESSION_ERR:DOM XPath例外51'を取得します – Staeff

+0

@staeff:そのようなエラーメッセージは、あなたのコピー/貼り付けが間違っていて、式を正確にコピーしなかったことを意味します。私の答えのXPath式は、XPath 1.0とXPath 2.0の両方で有効です。 –

関連する問題