2014-05-06 197 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

酷。很高興我能幫上忙 –