3

次のコードがあります。

<g xmlns="http://www.w3.org/2000/svg" id="MainMenu1" display="block" transform="translate(1125, 0)">
   <g dp:id="Content" xmlns:dp="http://dreampark.se/extensions" width="375" height="624" id="MainMenuViewMainMenu_DynamicChild3Content" _shadowId="MainMenuViewMainMenu_DynamicChild3Content">
      <g transform="translate(0,0)" x="0" y="0" clip-path="url(#clipPath59)">
         <g display="block" transform=" translate(0,208)">
            <g id="RootMenuItem" width="376" height="50" display="block" buffered-rendering="static" transform="translate(0,0)">
               <g id="RootMenuItemIconHolder" transform="translate(25,2)" display="none">
                  <image id="RootMenuItemIcon" opacity="1.0" width="40" height="40" display="block"/>
               </g>
               <foreignObject width="260" height="30" x="65" y="10" transform="null">
                  <body xmlns="http://www.w3.org/1999/xhtml">
                     <div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#AAACAE" font-size="22" width="298">Text 2</div>
                  </body>
               </foreignObject>
            </g>
            <g id="RootMenuItem" width="376" height="50" display="block" buffered-rendering="static" transform="translate(0,52)">
               <g id="RootMenuItemIconHolder" transform="translate(25,2)" display="block">
                  <image id="RootMenuItemIcon" opacity="1.0" width="40" height="40" display="block"/>
               </g>
               <foreignObject width="260" height="30" x="65" y="10" transform="null">
                  <body xmlns="http://www.w3.org/1999/xhtml">
                     <div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#1D212D" font-size="22" width="298">Text 1</div>
                  </body>
               </foreignObject>
            </g>
         </g>
      </g>
   </g>
</g>

要素を検索したいのですが、この要素が、属性に値を持つ子を持つ要素 ( )のid="RootMenuItemText"兄弟に続く要素の子である必要がありidます。"RootMenuItem"id="RootMenuItemIconHolder""block""display"

私が見つける必要がある要素は次のとおりです。

<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:22;color:#AAACAE" id="RootMenuItemText" original_x="null" fill="#1D212D" font-size="22" width="298">Text 1</div>

私はこのXpathを試しました:

//*[@id="RootMenuItemIconHolder"][@display='block']/following-sibling::*[last()]

しかし、それは要素を見つけていません。要素を見つけるのにどのXpath式が役立つか知っている人はいますか? 前もって感謝します。

4

1 に答える 1

1

以下を試してください:

//*[@id="RootMenuItemIconHolder"][@display='block']/following-sibling::*[last()]/descendant::div[@id='RootMenuItemText']

また、選択を機能させるには適切な名前空間を設定する必要があることも覚えておく必要があります。これxmlnsは、ドキュメントがドキュメントのさまざまなレベルで既定の xml 名前空間を使用しているためです。

于 2013-09-27T16:36:10.037 に答える