<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {mso-style-builtin:yes;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        mso-style-builtin:yes;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        mso-style-builtin:yes;
        color:purple;
        text-decoration:underline;}
span.gmailquote
        {mso-style-name:gmail_quote;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Do you mean copying & pasting this to the console? Or is this
some issue you run into when actually using pyexpat?<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Segoe UI","sans-serif"'>From:</span></b><span
style='font-size:9.0pt;font-family:"Segoe UI","sans-serif"'>
users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On
Behalf Of </b>Sridevi Aishwariya<br>
<b>Sent:</b> Monday, August 07, 2006 9:47 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] pyexpat and IronPython<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>__slots__ = [<br>
"StartElementHandler",<br>
"EndElementHandler",<br>
"CharacterDataHandler",<br>
]<br>
gives an error<o:p></o:p></p>
<div>
<p class=MsoNormal><span class=gmailquote>On 8/5/06, <b>Mark Rees</b> <<a
href="mailto:mark.john.rees@gmail.com">mark.john.rees@gmail.com</a>> wrote:</span>
<o:p></o:p></p>
<p class=MsoNormal>Hi,<br>
<br>
Seo has already done a basic pyexpat wrapper. He posted about it in:<br>
<br>
<a
href="http://lists.ironpython.com/pipermail/users-ironpython.com/2005-November/001227.html">http://lists.ironpython.com/pipermail/users-ironpython.com/2005-November/001227.html</a><br>
<br>
And it can be found at:<br>
<br>
<a href="http://sparcs.kaist.ac.kr/~tinuviel/fepy/old/pyexpat.py">http://sparcs.kaist.ac.kr/~tinuviel/fepy/old/pyexpat.py
</a><br>
<br>
I have used this with ElementTree. There are limitations like iterparse<br>
doesn't work and if the XML you are parsing contains an empty element<br>
i.e <doc /> it fails. I have modified Seo's pyexpat.py to handle the <br>
second limitation and have included the source in this email. I have<br>
used this for my elementtree requirements but the XML I parse is simple<br>
so there may be other as yet undiscovered issues.<br>
<br>
Regards<br>
<br>
Mark<br>
<br>
Modified version of pyexpat from<br>
<a href="http://sparcs.kaist.ac.kr/~tinuviel/fepy/old/pyexpat.py">http://sparcs.kaist.ac.kr/~tinuviel/fepy/old/pyexpat.py</a><br>
<br>
<br>
import clr<br>
clr.AddReference(" System.Xml")<br>
<br>
from System.IO import MemoryStream, SeekOrigin, StreamWriter<br>
from System.Xml import NameTable, XmlNamespaceManager, XmlParserContext,<br>
XmlSpace<br>
from System.Xml import XmlTextReader, XmlNodeType <br>
<br>
def ErrorString(errno):<br>
if errno > 0:<br>
return "unknown error"<br>
else:<br>
return None<br>
<br>
def ParserCreate(*args):<br>
return xmlparser()<br>
<br>
class xmlparser:<br>
<br>
__slots__ = [ <br>
"StartElementHandler",<br>
"EndElementHandler",<br>
"CharacterDataHandler",<br>
]<br>
<br>
returns_unicode = False<br>
<br>
def __init__(self):<br>
self._stream = MemoryStream() <br>
self._parser = self._make_parser()<br>
<br>
def Parse(self, data, isfinal=False):<br>
self._append_stream(data)<br>
self._parse()<br>
if isfinal:<br>
self._stream.Close()<br>
<br>
def _make_parser(self): <br>
table = NameTable()<br>
manager = XmlNamespaceManager(table)<br>
parser = XmlParserContext(table, manager,
None, XmlSpace.None)<br>
return parser<br>
<br>
def _append_stream(self, data):<br>
stream = self._stream <br>
position = stream.Position<br>
stream.Seek(0, SeekOrigin.End)<br>
writer = StreamWriter(stream)<br>
writer.Write(data)<br>
writer.Flush()<br>
stream.Position = position<br>
<br>
def _parse(self): <br>
reader = XmlTextReader(self._stream,
XmlNodeType.Element,<br>
self._parser)<br>
while reader.Read():<br>
nodetype =
reader.NodeType<br>
if nodetype ==
XmlNodeType.Element:<br>
name = reader.Name<br>
attributes = {}<br>
while reader.MoveToNextAttribute():<br>
attributes[reader.Name] = reader.Value<br>
if hasattr(self, "StartElementHandler"): <br>
self.StartElementHandler(name, attributes)<br>
# Create EndElement event as XmlTextReader doesn't<br>
# do this for empty elements<br>
if reader.IsEmptyElement :<br>
nodetype = XmlNodeType.EndElement<br>
if nodetype ==
XmlNodeType.EndElement:<br>
name = reader.Name<br>
if hasattr(self, "EndElementHandler"):<br>
self.EndElementHandler(name)<br>
elif nodetype ==
XmlNodeType.Text:<br>
data = reader.Value<br>
if hasattr(self, "CharacterDataHandler"):<br>
self.CharacterDataHandler (data)<br>
<br>
<br>
<br>
<br>
<br>
<br>
Monty Taylor wrote:<br>
> You could write a Python or C# wrapper around System.XML that behaves<br>
> like pyexpat and contribute it. :)<br>
><br>
> Monty<br>
><br>
> On 8/4/06, Bruce Christensen < <a href="mailto:t-bruch@microsoft.com">t-bruch@microsoft.com</a>>
wrote:<br>
><br>
>> Nope. :) pyexpat relies on Python extension modules written in C,
which<br>
>> don't work with IronPython. However, you can use the classes in the
.NET <br>
>> System.Xml namespace for parsing XML documents if you're writing new<br>
>> code.<br>
>><br>
>> --Bruce<br>
>><br>
>> -----Original Message-----<br>
>> From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>
>> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>]
On Behalf Of Sridevi<br>
>> Sent: Thursday, August 03, 2006 5:41 AM <br>
>> To: <a href="mailto:users-ironpython.com@lists.ironpython.com">users-ironpython.com@lists.ironpython.com</a><br>
>> Subject: [IronPython] pyexpat and IronPython<br>
>><br>
>> Iam unable to run pyexpat from IronPython <br>
>> Is there any files i got to add for it<br>
>><br>
>> _______________________________________________<br>
>> users mailing list<br>
>> <a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com
</a><br>
>> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
>> _______________________________________________<br>
>> users mailing list <br>
>> <a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com</a><br>
>> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
</a><br>
>><br>
>><br>
> _______________________________________________<br>
> users mailing list<br>
> <a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com</a><br>
> <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
><br>
><br>
<br>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com </a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>