Questions on XML

Kee Nethery kee at kagi.com
Sat Aug 22 08:09:36 CEST 2009


On Aug 21, 2009, at 7:15 PM, joy99 wrote:

> Dear Group,
>
> I like to convert some simple strings of natural language to XML. May
> I use Python to do this? If any one can help me, on this.
>
> I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I
> use Python to help me in this regard?

As a newbie, the thing that caused me trouble was importing a string  
into the XML parser. The parser seemed to want to open a file and I  
had a string. The solution was one of these:

from xml.etree import ElementTree as et
theXmlDataTree = et.parse(StringIO.StringIO(theXmlString))


from xml.etree import ElementTree as et
theXmlDataTree = et.ElementTree(et.XML(theXmlString))

Not sure which you would use nor what the differences are. I have the  
first set commented out in my code so for some reason I switched to  
the second set of code to take a string and pull it into the XML parser.

Once the string is in the parser, all the examples worked. It was  
getting it into the parser that had me stumped because none of the  
examples showed this situation, it appears to be obvious to someone  
who has used Python for a while.

Kee



More information about the Python-list mailing list