By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

Using ElementTree to tidy up an XML string to my liking

P: n/a
I have an XML string coming in from one system that I'd like to tidy up
and return in a very particular format. I'm picky!

If the input is
<SOMETHING attr1="foo1"
attr2='foo2' >

Then the output must be
<something
attr1="foo1"
attr2="foo2">

The file might have comments and namespaces and all of this should be
preserved as it was when it came in.

I was hoping to use ElementTree which can parse my input so that I rest
on solid foundations instead of mad regular expressions and string
manipulation.
But, if mad regular expressions and string manipulations is what it
takes I'll have to settle on that.

What are my options?

Feb 23 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
...I hope that you are aware that xml is *case sensitive*

Feb 24 '06 #2

P: n/a
Yes I am but, I'm using a DOM Serializer in Firefox which for some
reason turns myCamelNames into MYCAMELNAMES for the nodenames. I'll
therefore need to control the case-spelling of these things as I'm
formatting the XML string.

Feb 24 '06 #3

P: n/a
pe*****@gmail.com wrote:
Yes I am but, I'm using a DOM Serializer in Firefox which for some
reason turns myCamelNames into MYCAMELNAMES for the nodenames. I'll
therefore need to control the case-spelling of these things as I'm
formatting the XML string.


I realize that it's difficult to make sure that every user of your
system has a corrected Firefox, but it seems to me that there is
a bug in that DOM Serializer, and that it would be good to mend
that.

Concerning element names, it's your coice of course, but I agree
more and more with Guido and PEP008 that camelCase is ugly. (Not
that ALLCAPS is better...)
Feb 24 '06 #4

P: n/a
pe*****@gmail.com wrote:
Yes I am but, I'm using a DOM Serializer in Firefox which for some
reason turns myCamelNames into MYCAMELNAMES for the nodenames. I'll
therefore need to control the case-spelling of these things as I'm
formatting the XML string.


I am almost certain there is something wrong you are doing in Mozilla if
that is happening. My first guess is that you are really doing HTML even
thought you think you are doing XML, and therefore Mozilla converts your
stuff to uppercase. Without seeing the source it is hard to say. I would
advice you write to the Mozilla forums for advice on that.

--
Heikki Toivonen
Feb 24 '06 #5

P: n/a
On Fri, 24 Feb 2006 18:21:59 +0100, Magnus Lycka wrote:
Concerning element names, it's your coice of course, but I agree
more and more with Guido and PEP008 that camelCase is ugly. (Not
that ALLCAPS is better...)


I can see in PEP008 where it says Capitalized_Words_With_Underscores is
ugly, but I can't see where it says pure camelCase is ugly ?

--
Richard
Feb 25 '06 #6

P: n/a
Richard Townsend wrote:
On Fri, 24 Feb 2006 18:21:59 +0100, Magnus Lycka wrote:
Concerning element names, it's your coice of course, but I agree
more and more with Guido and PEP008 that camelCase is ugly. (Not
that ALLCAPS is better...)


I can see in PEP008 where it says Capitalized_Words_With_Underscores is
ugly, but I can't see where it says pure camelCase is ugly ?


Sorry, meant mixedCase (as it was in the XML example). Peter confused
me by writing "myCamelNames"

"""
Function Names

Function names should be lowercase, possibly with words separated by
underscores to improve readability. mixedCase is allowed only in
contexts where that's already the prevailing style (e.g. threading.py),
to retain backwards compatibility.

Method Names and Instance Variables

The story is largely the same as with functions: in general, use
lowercase with words separated by underscores as necessary to improve
readability.
"""
Feb 27 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.