0

I am trying to parse an xml string in python. I am searching for specific tag ops:cpc in the string. How can I get the actual value? In the example given below, the expected result is A61K9/00.

content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<ops:world-patent-data xmlns:ops="http://ops.epo.org" xmlns:reg="http://www.epo.org/register" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cpc="http://www.epo.org/cpcexport" xmlns:cpcdef="http://www.epo.org/cpcdefinition">\n    <ops:meta name="elapsed-time" value="20"/>\n    <ops:classification-scheme>\n        <ops:mappings inputSchema="ECLA" outputSchema="CPC">\n            <ops:mapping additional-only="false">\n                <ops:ecla>A61K9/00</ops:ecla>\n                <ops:cpc xlink:href="classification/cpc/A61K9/00">A61K9/00</ops:cpc>\n            </ops:mapping>\n        </ops:mappings>\n    </ops:classification-scheme>\n</ops:world-patent-data>\n'

xmldoc = minidom.parseString(content)
itemlist = xmldoc.getElementsByTagName('ops:cpc')
print len(itemlist)
2
  • Why not use triple quotes? That was much more readable. Commented Dec 12, 2013 at 21:20
  • this is how my GET is giving me the result which I want to process. Commented Dec 12, 2013 at 21:23

1 Answer 1

2

Use nodeValue property for a child text node:

>>> itemlist[0].childNodes[0].nodeValue
u'A61K9/00'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.