XML How-To
jj
jj at void.si
Thu May 31 02:25:54 EDT 2001
text = '''
<collection>
<comic title="Sandman" number='62'>
<writer>Neil Gaiman</writer>
<penciller pages='1-9,18-24'>Glyn Dillon</penciller>
<penciller pages="10-17">Charles Vess</penciller>
</comic>
</collection>
'''
# using Python XML package && 4suite
from xml.dom.ext.reader import Sax2
import xml.xpath
doc = Sax2.FromXml(text)
parser = xml.xpath.XPathParser.XPathParser()
parsed = parser.parseExpression('/collection/comic/@title')
root = xml.xpath.Context.Context(doc.documentElement)
nodeSet = parsed.evaluate(root)
print nodeSet[0].nodeValue
# writer
nodeSet =
parser.parseExpression('/collection/comic/writer/text()').evaluate(root)
print nodeSet[0].nodeValue
JJ
On 30 May 2001 13:59:21 -0700, vdanovich at empireone.net (Vyacheslav
Danovich) wrote:
>Hi folks!
>
>When using xml.sax module and the following file is given:
>
><collection>
> <comic title="Sandman" number='62'>
> <writer>Neil Gaiman</writer>
> <penciller pages='1-9,18-24'>Glyn Dillon</penciller>
> <penciller pages="10-17">Charles Vess</penciller>
> </comic>
></collection>
>
>and I know the title and the number of the 'comic'
>How can I find out the value for <writer>?
>
>Any help is appreciated!
More information about the Python-list
mailing list