I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<w:document xmlns:w="http://ift.tt/JiuBoE" xmlns:m="http://ift.tt/JiuBoH" xmlns:mc="http://ift.tt/pzd6Lm" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://ift.tt/1bA4cfb" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://ift.tt/1bA4bYS" xmlns:w15="http://ift.tt/Ua2VHY" xmlns:wne="http://ift.tt/JiuB8g" xmlns:wp="http://ift.tt/JiuBoF" xmlns:wp14="http://ift.tt/1bA4bYX" xmlns:wpc="http://ift.tt/JiuBoL" xmlns:wpg="http://ift.tt/JiuB8i" xmlns:wpi="http://ift.tt/1bA4bYO" xmlns:wps="http://ift.tt/1bA4djs" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p w:rsidR="00DD23CE" w:rsidRPr="00D1434D" w:rsidRDefault="009764DB" w:rsidP="00660FF7">
<w:pPr>
<w:pStyle w:val="HTMLPreformatted" />
<w:spacing w:line="276" w:lineRule="auto" />
<w:jc w:val="both" />
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman" />
<w:b />
<w:color w:val="000000" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="0" w:name="_GoBack" />
<w:bookmarkEnd w:id="0" />
<w:r w:rsidRPr="00D1434D">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman" />
<w:b />
<w:color w:val="000000" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
<w:t xml:space="preserve">Responses to </w:t>
</w:r>
<w:r w:rsidR="00335D4A" w:rsidRPr="00D1434D">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman" />
<w:b />
<w:color w:val="000000" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
<w:lang w:eastAsia="ja-JP" />
</w:rPr>
<w:t>the Reviewer</w:t>
</w:r>
<w:r w:rsidR="00335D4A" w:rsidRPr="00D1434D">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman" />
<w:b />
<w:color w:val="000000" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
<w:t xml:space="preserve">\xe2\x80\x99s </w:t>
</w:r>
<w:r w:rsidR="00DD23CE" w:rsidRPr="00D1434D">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="MS PGothic" w:hAnsi="Times New Roman" />
<w:b />
<w:color w:val="000000" />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
<w:t>Comments</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00200734" w:rsidRPr="00D1434D" w:rsidRDefault="00200734" w:rsidP="00660FF7">
<w:pPr>
<w:spacing w:line="276" w:lineRule="auto" />
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" />
<w:b />
<w:bCs />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00675BBA" w:rsidRPr="00D1434D" w:rsidRDefault="00675BBA" w:rsidP="00660FF7">
<w:pPr>
<w:spacing w:line="276" w:lineRule="auto" />
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" />
<w:b />
<w:bCs />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
</w:pPr>
<w:r w:rsidRPr="00D1434D">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" />
<w:b />
<w:bCs />
<w:sz w:val="24" />
<w:szCs w:val="24" />
<w:highlight w:val="yellow" />
</w:rPr>
<w:t>Comments of Reviewer 1</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
I need to extract text with the w:highlight tag and its attribute value as yellow. I was referring to the tutorials on xml. I have managed to get the text without specifying the attribute value with the following:
w = "http://ift.tt/JiuBoE"
for p in lxml_tree.findall('.//{' + w + '}p'):
for t in p.findall('.//{%(ns)s}highlight/../..//{%(ns)s}t' %{'ns':w}):
print t.text
but it doesn't return anything when I specify the attribute value:
w = "http://ift.tt/JiuBoE"
for p in lxml_tree.findall('.//{' + w + '}p'):
for t in p.findall('.//{%(ns)s}highlight[@val="yellow"]/../..//{%(ns)s}t' %{'ns':w}):
print t.text
What is the problem??
No comments:
Post a Comment