我試圖讓W的屬性:從所有W的rsidR值:插件和W:使用德爾項下面的XML引入nokogiri:如何獲得一個引入nokogiri的孩子節點集
<w:document mc:Ignorable="w14 w15 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<w:body>
<w:p w14:paraId="56037BEC" w14:textId="1188FA30" w:rsidR="001665B3" w:rsidRDefault="008B4AC6">
<w:r>
<w:t xml:space="preserve">This is the story of a man who </w:t>
</w:r>
<w:ins w:author="Mitchell Gould" w:date="2016-09-28T09:15:00Z" w:id="0">
<w:r w:rsidR="003566BF">
<w:t>went</w:t>
</w:r>
</w:ins>
<w:del w:author="Mitchell Gould" w:date="2016-09-28T09:15:00Z" w:id="1">
<w:r w:rsidDel="003566BF">
<w:delText>goes</w:delText>
</w:r>
</w:del>
<w:r>
<w:t xml:space="preserve">to the store to </w:t>
</w:r>
<w:ins w:author="Mitchell Gould" w:date="2016-09-28T09:15:00Z" w:id="2">
<w:r w:rsidR="003566BF">
<w:t>purchase</w:t>
</w:r>
</w:ins>
...
</w:p>
</w:body>
</w:document>
我使用Ruby郵編解壓縮的docx文件如下:
zip = Zip::File.open("test.docx")
doc = zip.find_entry("word/document.xml")
file = Nokogiri::XML.parse(doc.get_input_stream)
到目前爲止,我有以下幾點:
file.xpath('//w:ins').each do |n|
puts n.children
puts n.children.attr('w:rsidR')
end
哪個產生:
<w:r w:rsidR="003566BF">
<w:t>went</w:t>
</w:r>
<w:r w:rsidR="003566BF">
<w:t>purchase</w:t>
</w:r>
<w:r w:rsidR="008C3761">
<w:t>replace</w:t>
</w:r>
<w:r w:rsidR="009D3E86">
<w:t>place</w:t>
</w:r>
<w:r w:rsidR="00F633DF">
<w:t xml:space="preserve">was </w:t>
</w:r>
<w:r w:rsidR="00D46E57">
<w:t>was</w:t>
</w:r>
<w:r w:rsidR="00F56399">
<w:t xml:space="preserve"> sat</w:t>
</w:r>
我似乎無法正常訪問w:rsidR。我怎樣才能做到這一點?我只是開始與Nokogiri和麻煩。
非常感謝yenshirak。很有幫助。 – chell