DOCTYPE in XML
Vyacheslav Danovich
vdanovich at empireone.net
Thu May 31 14:24:03 EDT 2001
Thank you, jj.
This example'd worked fine and I almost started believing that my
problem'd been solved until I introduced the following:
<!DOCTYPE smtp
[
<!ENTITY successful_run SYSTEM "d:\python21\success.xml">
<!ENTITY faulty_run SYSTEM "d:\PYTHON21\fault.xml">
]>
<smtp>
<emailing>
<host>blah</host>
<sender>blahblah</sender>
<attachment>C:\log</attachment>
<receipients>sdanovich at test.com</receipients>
<receipients>vdanovich at empireone.net</receipients>
<receipients>vdanovich at hotmail.com</receipients>
</emailing>
<status>
<sagent run="0">
<subject>Run successfully completed</subject>
<text>&successful_run;</text>
</sagent>
<sagent run="1">
<subject>Run failed</subject>
<text>&faulty_run;</text>
</sagent>
</status>
</smtp>
and my python code is:
subject = ""
text = ""
doc = Sax2.FromXmlFile(file, validate=0)
parser = xml.xpath.XPathParser.XPathParser()
parsed = parser.parseExpression('/smtp/emailing')
root = xml.xpath.Context.Context(doc.documentElement)
nodeSet = parsed.evaluate(root)
Host_Name = parser.parseExpression('/smtp/emailing/host/text()').evaluate(root)
host = Host_Name[0].nodeValue
Sender_Name = parser.parseExpression('/smtp/emailing/sender/text()').evaluate(root)
sender = Sender_Name[0].nodeValue
Attachment_Name = parser.parseExpression('/smtp/emailing/attachment/text()').evaluate(root)
attachment = Attachment_Name[0].nodeValue
Receipients_Name = parser.parseExpression('/smtp/emailing/receipients/text()').evaluate(root)
receipients = []
for i in range(len(Receipients_Name)):
receipients.append(Receipients_Name[i].nodeValue)
parsed = parser.parseExpression('/smtp/status/sagent/@run')
root = xml.xpath.Context.Context(doc.documentElement)
nodeSet = parsed.evaluate(root)
for i in range(len(nodeSet)):
print "TEXT: " , text
if str(nodeSet[i].nodeValue) == str(status):
Subject_Name = parser.parseExpression('/smtp/status/sagent/subject/text()').evaluate(root)
subject = Subject_Name[i].nodeValue
Text_Name = parser.parseExpression('/smtp/status/sagent/text/text()').evaluate(root)
text = Text_Name[i].nodeValue
email(host, subject, sender, receipients, attachment, text)
At the end the values for "text" were the empty string ("")
It seems like the parser doesn't parse the DOCTYPE entities
>jj <jj at void.si> wrote in message >news:<ltobhtkb3lngrdn4neq9f7g8aetsstp5lv at 4ax.com>...
> 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