2017-02-15 6 views
0

Googleシートを使用してXMLデータを読み取っています。 残念ながら、私はXMLを正しく抽出するのに苦労しています。 https://www.w3schools.com/xml/xpath_syntax.asp、SOなどのGoogleの情報源が役に立たなかった出力は非常に追加の書式が必要なノードごとに2つの属性を取得する方法

www.profile1.com answer text 1.1 answer text 1.2 
www.profile2.com answer text 2.1 answer text 2.2 

バリアントが試み、スプレッドシートに要求されない次の形式であることが必要である

<item> 
    <profile_url>www.profile1.com</profile_url> 
    <answers> 
     <answers_item> 
      <answer>answer text 1.1</answer> 
     </answers_item> 
     <answers_item> 
      <answer>answer text 1.2</answer> 
     </answers_item> 
    </answers> 
<item> 
<item> 
    <profile_url>www.profile2.com</profile_url> 
    <answers> 
     <answers_item> 
      <answer>answer text 2.1</answer> 
     </answers_item> 
     <answers_item> 
      <answer>answer text 2.2</answer> 
     </answers_item> 
    </answers> 
<item> 

下に簡略化されたデータの処理中

を与えることができませんでした正しい出力は

"//profile_url //answers/answers_item/answer" 
"//profile_url | //answers/answers_item/answer" 

ありがとうございます事前にXPathが使用されるかもしれないので、文字列参加

string-join(//item/(concat(profile_url/text(), '.', answers/answers_item/answer//text())), "&#10;") 

を使用ロブ

suggested duplicate

1から


試み修正)は(追従誤差を与えた2.0ない)

Imported Xml content can not be parsed. 

2)使用方法

concat(//profile_url/text(), " ", //answers/answers_item/answer/text()) 

最初のエントリのみを与えます。第二の場合は最初のitem

ため

www.profile1.com answer text 1.1 answer text 1.2

+1

[xpathに複数のノード値を連結する](http://stackoverflow.com/questions/21996965/concatenate-multiple-node-values-in-xpath)の可能な複製 – Andersson

+0

提案された複製の失敗した結果を追加しました。 –

答えて

0

として必要な出力を与えるべき、あなたは各itemに2つだけanswers_item秒を持って次のXPath

concat(//item[1]/profile_url, " ", //item[1]/answers/answers_item[1]/answer, " " , //item[1]/answers/answers_item[2]/answer)

を想定すると、 1つ、修正する必要がありますitem[1]item[2]

これは、Javaで作業している場合は簡単に実行できます。

+0

ありがとうございますが、処理するレコードは6000件あり、スプレッドシートに出力されるため、Javaは存在しません。その反復はXPathステートメント内で実行する必要があります。 –

+0

「no java」と言うとき、これはすべてWebページそのもので起こっているということですか?もしそうなら、JavascriptやVBScriptを使ってここで必要なものを達成する必要があるように思えます。 「スプレッドシートにデータを取得する」ために、これは何を使用していますか? –

+0

@RobertSharpe 'XPathステートメント内で反復処理が必要です。あなたの要求には不可能です。すべてのノードを印刷するのに 'concat'を使うことはできません。ノード自体は取得できますが、必要な形式で連結されたテキストは取得できません。どのようにXPath式を評価していますか?どのエンジン? – SomeDude