2014-05-06 167 views
0

我有以下XML结构。我可以确定突出显示的<story contenttype="News" id="cbc655617-ba25-4629-b2a2-073ba2369758">节点,并且需要到达通过XPath突出显示的<packagesection id="264311652" navTitle="News">节点。你可以请一个能够识别相同的XPath表达式来帮忙吗?我将无法使用navTitle属性,因为它是动态的,但我只知道packagesection节点必须是最顶层的父的第一级子为故事节点在XPath中选择特定节点

<?xml version="1.0" encoding="UTF-8"?> 
<package id="cfc35dc14-5345-42a4-b4f9-0b833e3fde3a"> 
    <title>Gas Daily</title> 
    <sectionelement> 
     <packagesection id="264311518" navTitle="Gas Daily"> 
      <sectionelement> 
       <packagesection id="264311652" navTitle="News"> 
        <sectionelement> 
         <packagesection id="264679044" navTitle="Test1"> 
          <sectionelement> 
           <packagesection id="264679046" navTitle="Test2"> 
            <sectionelement> 
             <topicref format="xml" 
              href="cbc655617-ba25-4629-b2a2-073ba2369758" id="264679396" 
              sequence="1" type="story"> 
              <story contenttype="News" 
               id="cbc655617-ba25-4629-b2a2-073ba2369758"> 
               <slug>test_arko_20140502_special_byline</slug> 
               <storyTitlealts> 
                <headline>test_arko_20140502_special_byline</headline> 
               </storyTitlealts> 
               <lead>test_arko_20140502_special_byline</lead> 
               <storybody> 
                <p id="43102552-91a9-44a5-af4a-72b742460a5b">test_arko_20140502_special_byline</p> 
               </storybody> 
              </story> 
             </topicref> 
            </sectionelement> 
           </packagesection> 
          </sectionelement> 
          <sectionelement> 
           <topicref format="xml" 
            href="c177f4ddd-e983-4730-b835-c7724178b223" id="264679820" 
            sequence="2" type="story"> 
            <story contenttype="News" 
             id="c177f4ddd-e983-4730-b835-c7724178b223"> 
             <slug>nothing</slug> 
             <storyTitlealts> 
              <headline>nothing</headline> 
             </storyTitlealts> 
             <lead>nothing</lead> 
             <storybody> 
              <p id="d558b9ac-5b28-4690-bb0c-664ccbe14e8f">nothing</p> 
             </storybody> 
            </story> 
           </topicref> 
          </sectionelement> 
         </packagesection> 
        </sectionelement> 
       </packagesection> 
      </sectionelement> 
      <sectionelement> 
       *<packagesection id="264679052" navTitle="Test5">* 
        <sectionelement> 
         <topicref format="xml" href="c16f1fca2-31ed-4973-b201-a5a089c788a6" 
          id="264679826" sequence="12" type="story"> 
          **<story contenttype="News" id="c16f1fca2-31ed-4973-b201-a5a089c788a6">** 
           <slug>test story stringer3</slug> 
           <storyTitlealts> 
            <headline>test story stringer3</headline> 
           </storyTitlealts> 
           <lead>test story stringer3</lead> 
           <storybody> 
            <p id="c5d5c883-d860-46fa-b035-64c13a5fcd23">test story stringer3</p> 
           </storybody> 
          </story> 
         </topicref> 
        </sectionelement> 
       </packagesection> 
      </sectionelement> 
     </packagesection> 
    </sectionelement> 
</package> 
+0

我曾尝试以下: /剧情/祖先:: packagesection [@ navTitle = '气日报']/sectionelement/packagesection ,我让所有packagesection元素 – ArinCool

+0

什么'(// sectionelement/packagesection [@ navTitle ='Gas Daily'] //故事[predicate-to-filter-on-the-story-you-want]] [1]'? –

+0

感谢您的回复保罗。我需要获取packagesection元素而不是故事元素。请建议 – ArinCool

回答

0

我试着用下面的xpath,它工作。感谢你保罗的帮助!

//sectionelement/packagesection[@navTitle="Gas Daily"]/sectionelement/packagesection[descendant::story[@id=$id] or descendant::analytic[@id=$id]] 
+0

酷。很高兴我能帮上忙 –