
orange
User
Jun 28, 2017, 12:34 AM
Post #1 of 2
(5913 views)
|
to parse docx, I first extract document.xml from it with 7z. then I use standard LibXML parser. but to do that, I have to filter it like this:
$content =~ s/<\/w:t><\/w:r><w:r w:rsidR(Pr|)=".{8}"><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:lang w:val="en-IN"\/>|)<\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:r w:rsidR(Pr|)=".{8}"( w:rsidRPr=".{8}"|)><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:bCs\/>|<w:b\/>|)<\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:r (w:rsidR=".{8}" |)w:rsidRPr=".{8}"><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:bCs\/>|<w:b\/><w:i\/>|<w:lang w:val="en-IN"\/>|)<\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:proofErr w:type="(spellStart|spellEnd)"\/><w:r( w:rsidR=".{8}" w:rsidRPr=".{8}"| w:rsidRPr=".{8}"|)><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/><w:lang w:val="en-IN"\/><\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:proofErr w:type="spellEnd"\/><w:proofErr w:type="gramEnd"\/><w:r( w:rsidR=".{8}" w:rsidRPr=".{8}"| w:rsidRPr=".{8}"|)><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/><w:lang w:val="en-IN"\/><\/w:rPr><w:t xml:space="preserve">//g; $content =~ s/<\/w:t><\/w:r><w:proofErr w:type="gramEnd"\/><w:r( w:rsidRPr=".{8}"|)><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:lang w:val="en-IN"\/>|)<\/w:rPr><w:t xml:space="preserve">//g; $content =~ s/<\/w:t><\/w:r><w:bookmarkStart w:id="\d+" w:name="OLE_LINK\d+"\/>(<w:bookmarkStart w:id="\d+" w:name="OLE_LINK\d+"\/>|)(<w:bookmarkStart w:id="\d+" w:name="OLE_LINK\d+"\/>|)<w:r( w:rsidR=".{8}" w:rsidRPr=".{8}"|)><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:lang w:val="en-IN"\/>|)<\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/>(<w:b\/>|<w:lang w:val="en-IN"\/>|)<\/w:rPr><w:t( xml:space="preserve"|)>//g; $content =~ s/<\/w:t><\/w:r><w:r w:rsidR=".{8}"><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/><w:b\/><w:i\/><\/w:rPr><w:t>//g; $content =~ s/<\/w:t><\/w:r><w:proofErr w:type="gramEnd"\/><w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"\/><\/w:rPr><w:t>//g; is there some better way to filter out those tags? thanks.
|