2016-06-16 6 views
0

以下のサンプルxmlに従って、同じ順序でテキストを解析する必要があります。私はノードの値を取得するためにfind()メソッドを使用していますが、すべての段落が一緒に結合され、すべてのマルチメディアが一緒に結合されています。すべてのヘルプ 以下のような期待を取得するために、出力はあなたが使用することができます jqueryで重複する子でxmlを解析するには?

 <section ID="warn"> 
      <title>WARNINGS</title> 
      <text> 
       <paragraph>first sample text</paragraph> 
       <multimedia>sample Media1</multimedia> 
       <paragraph>Second sample text</paragraph> 
       <paragraph>Third sample text</paragraph> 
       <paragraph>Fourth sample text</paragraph> 
       <multimedia>sample Media2</multimedia> 
       <paragraph>Fifth sample text</paragraph> 
      </text> 

    </component> 

Expected output should be like below 

WARNINGS 
first sample text 
sample Media1 
Second sample text 
Third sample text 
Fourth sample text 
sample Media2 

答えて

0

をいただければ幸いどう

var nodes = $("section *").filter(function() { 
    return $(this).children().length == 0; 
}); 

nodes.each(function() { 
    console.log($(this).text()); 
}); 

Fiddle

  • エンド・ノードをフィルタリング、子要素を持たない
  • それから、その中のテキストを取得するためにループします。
+1

ありがとうございます – prasad

関連する問題