2016-01-08 36 views
-1

這裏是我期待搶word文檔的一部分:引入nokogiri和XML - 抓鬥「TR」 XML包含特定文本

 <w:tr> 
      <w:tc> 
       <w:tcPr> 
        <w:tcW w:type="dxa" w:w="9035"/> 
        <w:tcBorders> 
         <w:top w:color="0A57A4" w:space="0" w:sz="6" w:val="single"/> 
        </w:tcBorders> 
        <w:vAlign w:val="center"/> 
       </w:tcPr> 
       <w:p> 
        <w:pPr> 
         <w:jc w:val="left"/> 
        </w:pPr> 
        <w:r> 
         <w:t>#Finding#</w:t> 
        </w:r> 
        <w:bookmarkStart w:id="49" w:name="_GoBack"/> 
        <w:bookmarkEnd w:id="49"/> 
       </w:p> 
      </w:tc> 
      <w:tc> 
       <w:tcPr> 
        <w:tcW w:type="dxa" w:w="1705"/> 
        <w:tcBorders> 
         <w:top w:color="0A57A4" w:space="0" w:sz="6" w:val="single"/> 
        </w:tcBorders> 
        <w:vAlign w:val="center"/> 
       </w:tcPr> 
       <w:p> 
        <w:r> 
         <w:rPr> 
          <w:noProof/> 
         </w:rPr> 
         <w:drawing> 
          <wp:inline distB="0" distL="0" distR="0" distT="0"> 
           <wp:extent cx="292608" cy="292608"/> 
           <wp:effectExtent b="0" l="0" r="0" t="0"/> 
           <wp:docPr id="924" name="Picture 924"/> 
           <wp:cNvGraphicFramePr> 
            <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/> 
           </wp:cNvGraphicFramePr> 
           <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 
            <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
             <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
              <pic:nvPicPr> 
               <pic:cNvPr id="0" name="S-sm.png"/> 
               <pic:cNvPicPr/> 
              </pic:nvPicPr> 
              <pic:blipFill> 
               <a:blip cstate="print" r:embed="rId20"> 
                <a:extLst> 
                 <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"> 
                  <a14:useLocalDpi val="0" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"/> 
                 </a:ext> 
                </a:extLst> 
               </a:blip> 
               <a:stretch> 
                <a:fillRect/> 
               </a:stretch> 
              </pic:blipFill> 
              <pic:spPr> 
               <a:xfrm> 
                <a:off x="0" y="0"/> 
                <a:ext cx="292608" cy="292608"/> 
               </a:xfrm> 
               <a:prstGeom prst="rect"> 
                <a:avLst/> 
               </a:prstGeom> 
              </pic:spPr> 
             </pic:pic> 
            </a:graphicData> 
           </a:graphic> 
          </wp:inline> 
         </w:drawing> 
        </w:r> 
       </w:p> 
      </w:tc> 
     </w:tr> 

有沒有辦法有引入nokogiri抓住整個<w:tr>所有通向</w:tr>(結尾)的地方,「#Finding#」存在嗎?就像搜索包含#Finding#並抓取整個tr元素的文本中的所有「trs」一樣?我是否必須遍歷整個文檔中的每個<w:tr>標記,並查看它是否包含#Finding#中的內容?

+0

請閱讀「[mcve]」和「[問]」。我們期望看到您嘗試解決問題。這意味着顯示你搜索的內容,爲什麼它沒有幫助,或者你的代碼來解決問題。因爲它看起來像你要求我們爲你寫代碼,這不是它的目的。 –

回答

1

有沒有辦法有引入nokogiri抓住其中"#Finding#"存在整個<w:tr>一路到</w:tr>(結束)?

的XPath

//w:tr[.//w:t[contains(., '#Finding#')]] 

用簡單的英語 「具有<w:t>包含#Finding#任何<w:tr>」。

注:

+0

哇。將指甲打在頭上。非常豐富和非常感謝!奇蹟般有效! – LewlSauce