tag:blogger.com,1999:blog-10678074.post5323185330852740615..comments2024-03-28T07:16:45.478+00:00Comments on making apps, making webs.: Pretty print xml with python - indenting xml.Unknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-10678074.post-88770775712488120582023-07-18T08:01:43.605+01:002023-07-18T08:01:43.605+01:00Prestige Park Grove is designed to offer residents...<a href="https://www.prestigesparkgrove.in" rel="nofollow">Prestige Park Grove</a> is designed to offer residents a lifestyle of opulence and comfort.Prestige Park Grovehttps://www.blogger.com/profile/05966019493469577882noreply@blogger.comtag:blogger.com,1999:blog-10678074.post-15953107341199787882010-10-16T03:33:43.815+01:002010-10-16T03:33:43.815+01:00I haven't used xml.dom.ext, but I've found...I haven't used xml.dom.ext, but I've found that `lxml.etree.tostring(lxml.etree.parse(filename))` runs at least 3x faster than prettyprinting with `xml.minidom`. This is not really surprising, since lxml wraps C libraries.Tedhttps://www.blogger.com/profile/15393025811070402542noreply@blogger.comtag:blogger.com,1999:blog-10678074.post-60564170465065507082009-10-02T13:43:36.897+01:002009-10-02T13:43:36.897+01:00xml.dom.minidom import parseString
Excellent tips...xml.dom.minidom import parseString<br /><br />Excellent tips !! Thank you so much !Unknownhttps://www.blogger.com/profile/14187599899135416202noreply@blogger.comtag:blogger.com,1999:blog-10678074.post-4377622436837154692009-03-13T14:25:00.000+00:002009-03-13T14:25:00.000+00:00To pretty print an ElementTree:from xml.minidom im...To pretty print an ElementTree:<BR/><BR/>from xml.minidom import parseString<BR/>from xml.etree import ElementTree<BR/><BR/>def prettyPrint(element):<BR/> txt = ElementTree.tostring(element)<BR/> print minidom.parseString(txt).toprettyxml()Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-10678074.post-41127156197463890702008-06-09T09:00:00.000+01:002008-06-09T09:00:00.000+01:00http://www.codeplex.com/xmlpphttp://www.codeplex.com/xmlppUnknownhttps://www.blogger.com/profile/02230796658435071711noreply@blogger.comtag:blogger.com,1999:blog-10678074.post-65841696965041481162007-05-21T14:42:00.000+01:002007-05-21T14:42:00.000+01:00The etree.tostring function in lxml has a pretty_p...The etree.tostring function in lxml has a pretty_print argument that can come in handy.<BR/><BR/>Mostly, though, I use <A HREF="http://infix.se/2007/02/06/gentlemen-indent-your-xml" REL="nofollow">a custom indent function</A> for both lxml and cElementTree trees.Filip Salomonssonhttps://www.blogger.com/profile/11425026095782309729noreply@blogger.comtag:blogger.com,1999:blog-10678074.post-58813705735543425472007-05-21T03:20:00.000+01:002007-05-21T03:20:00.000+01:00This method is pretty slow; I also found xml.dom.e...This method is pretty slow; I also found xml.dom.ext to be a little hard to install (is it maintained?).<BR/><BR/>The last time I revisited this problem, I would up using a pretty-printing XSLT with lxml as the XSLT interface. It's faster than the fairly slow xml.dom.ext.PrettyPrint.Danielhttps://www.blogger.com/profile/13890648911094881608noreply@blogger.com