[XML-SIG] validate file-like class object

Leticia Larrosa LETICIA at tesla.cujae.edu.cu
Sun Apr 10 21:48:20 CEST 2005


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






More information about the XML-SIG mailing list