Alternatives to XML?
Frank Millman
frank at chagford.com
Fri Aug 26 01:22:05 EDT 2016
"Peter Otten" wrote in message news:npn25e$s5n$1 at blaine.gmane.org...
Frank Millman wrote:
>> As you have to keep the "<", why bother?
>
> If you mean why don't I convert the '<' to '<', the answer is that I do
> - I just omitted to say so. However, explicit is better than implicit :-)
> Doesn't that make the XML document invalid or changes it in an
> irreversible way? How would you know whether
"<foo><bar/></foo>"
started out as
"<foo><bar/></foo>"
or
"<foo><bar/></foo>"
?
I cheat ;-)
It is *my* XML, and I know that I only use the offending characters inside
attributes, and attributes are the only place where double-quote marks are
allowed.
So this is my conversion routine -
lines = string.split('"') # split on attributes
for pos, line in enumerate(lines):
if pos%2: # every 2nd line is an attribute
lines[pos] = line.replace('<', '<').replace('>', '>')
return '"'.join(lines)
Frank
More information about the Python-list
mailing list