這是您的專家的XPath/OOXML問題。OOXML中的XPath
我有一個MSOffice docx,帶有不同顏色的高亮顯示的文本,我必須將其轉換爲XML,然後使用XPath標識所有高亮顯示的內容,而不考慮顏色,以便可以用XML規則對它們進行過濾。
下面是一個例子如何看起來的MSWord
我明白,我怎麼能選擇的子節點,如果它存在使用// w ^:P/W:R/W:RPR/W:亮點[@w:VAL =「黃色」]」 但不是如何可以選擇包含文本,如果在同一<w:r>
塊中存在的高亮節點的實際節點W:t
例:我需要選擇內<W:t>
文本如果<w:highlight>
存在於父代中節點,併爲文檔中的所有情況執行此操作。
所以在這個例子中,我需要選擇文本「這一個去,因爲它突出顯示黃色」,因爲它有一個w:與w:val黃色相關的高亮節點。
<w:r w:rsidRPr="003815B4">
<w:rPr>
<w:highlight w:val="yellow"/>
</w:rPr>
<w:t>This one goes because it is highlighted yellow</w:t>
</w:r>
任何幫助或指針將不勝感激:-)
這裏的DOCX的XML例子(與可讀性刪除OOXML頭)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<doc>
<w:body>
<w:p w:rsidR="00B93038" w:rsidRDefault="003815B4">
<w:r>
<w:t>This line stays because it is not highlighted in any colour</w:t>
</w:r>
</w:p>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r w:rsidRPr="003815B4">
<w:rPr>
<w:highlight w:val="yellow"/>
</w:rPr>
<w:t>This one goes because it is highlighted yellow</w:t>
</w:r>
</w:p>
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="4621"/>
<w:gridCol w:w="4621"/>
</w:tblGrid>
<w:tr w:rsidR="003815B4" w:rsidTr="003815B4">
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t>And so on</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r w:rsidRPr="003815B4">
<w:rPr>
<w:highlight w:val="cyan"/>
</w:rPr>
<w:t>Blue highlight</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr w:rsidR="003815B4" w:rsidTr="003815B4">
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t>Red</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t xml:space="preserve">Mixed </w:t>
</w:r>
<w:r w:rsidRPr="003815B4">
<w:rPr>
<w:highlight w:val="red"/>
</w:rPr>
<w:t>text</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve"> with </w:t>
</w:r>
<w:r w:rsidRPr="003815B4">
<w:rPr>
<w:highlight w:val="green"/>
</w:rPr>
<w:t>some highlighted</w:t>
</w:r>
<w:r>
<w:t xml:space="preserve"> and some not</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr w:rsidR="003815B4" w:rsidTr="003815B4">
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4"/>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4621" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4"/>
</w:tc>
</w:tr>
</w:tbl>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4"/>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t>Another highlight</w:t>
</w:r>
</w:p>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t>Some text</w:t>
</w:r>
</w:p>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4"/>
<w:p w:rsidR="003815B4" w:rsidRDefault="003815B4">
<w:r>
<w:t>End</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:sectPr w:rsidR="003815B4">
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</doc>
您使用XPath的環境是什麼? – 2014-12-02 19:16:10
你試過//w:p/w:r/w:t[../w:rPr/w:highlight/@w:val='yellow'] – JasonPlutext 2014-12-02 20:24:01
Mathias你好,它是Java和Sax Parser。 – user3012857 2014-12-03 01:00:40