[XML-SIG] validate file-like class object

Leticia Larrosa LETICIA at tesla.cujae.edu.cu
Sun Apr 10 22:31:01 CEST 2005


In my last email i have an error in the following two lines:
"
 xv.parse_resource(xml_fileIO)
 domTree = FromXmlStream(xml_fileIO)
"
 because i must to do a deep copy of the StringIO object first, because the  
"xv.parse_resource" close the file. The code must be:
"
xml_fileIOCopy = copy.deepcopy(xml_fileIO)
xv.parse_resource(xml_fileIO)
domTree = FromXmlStream(xml_fileIOCopy)
"

Please send me any suggestion about my last email.

Thanks in advance

-----Original Message-----
From: "Leticia Larrosa" <LETICIA at tesla.cujae.edu.cu>
To: "Andrew Clover" <and-xml at doxdesk.com>, xml-sig at python.org
Cc: 
Date: Sun, 10 Apr 2005 15:48:20 -0400
Subject: [XML-SIG] validate file-like class object

> Hi all!
> 
> I received a StringIO, file-like class object, that contain an XML. I
> need 
> parser it, but before i need validate it.
> Then I make a slight change to the
> "_xmlplus\parsers\xmlproc\xmlapp.py". I 
> replace the function "create_input_source" for:
> "
> def create_input_source(self,sysid):
>         if isinstance(sysid, StringIO.StringIO):
>             return sysid
>         elif sysid[1:3]==":\\" or urlparse.urlparse(sysid)[0] == '':
>             return open(sysid)
>         else:
>             return urllib2.urlopen(sysid)
> "
> 
> and add the following import line:
> 
> "import StringIO.StringIO"
> 
> As you can see, now "sysid" may be an StringIO instance. Read the
> following 
> code to see how i use the above change.
> 
> "
> from xml.parsers.xmlproc import xmlval
> from xml.dom.ext.reader.Sax2 import FromXmlStream
> 
> xv = xmlval.XMLValidator()
> #xml_fileIO is instance of StringIO.StringIO that contain an XML.
> xv.parse_resource(xml_fileIO)
> domTree = FromXmlStream(xml_fileIO)
> "
> Please send me any suggestion.
> 
> What can i do to incorporate this change in the standard library?
> 
> Thanks in advance
> 
> 
> 
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG at python.org
> http://mail.python.org/mailman/listinfo/xml-sig
> 
> 






More information about the XML-SIG mailing list