views:

88

answers:

1

So I have a DOM document that looks essentially like this

<categories>
    <category id="1"/>
    <category id="2"/>
</categories>

This is how the document previews in Firebug, as I would expect.

However, when I POST this to the server, I get

<categories>
    <CATEGORY id="1"/>
    <CATEGORY id="2"/>
</categories>

Indeed, doc.documentElement.firstChild.nodeName returns "CATEGORY". The nodes are added using jQuery.append('<category/>').

Why are the child tags returned in all caps?

+2  A: 

nodeName always returns the upper case name for HTML elements in DOMs treated as HTML ... not so for XML, however.

more info here

I'm not sure if this totally answers your question, but I'm guessing that part of the answer is your file is being treated like an HTML document, at least as far as nodeName is concerned.

Correction: It's JQuery that's treating things like HTML. From this previous Stack Overflow answer:

JQuery uses a hidden div innerHTML to build the child node, that's why the capitalization differs

I'm pretty sure you're experiencing the same issue as in that previous answer.

Tim Goodman
Thanks, +1 for the info. I've tried using DOMParser() and document.implementation.createDocument() to instantiate the object -- what else could I do to have it treated as XML?
harpo
Just added a bit to my answer... I'm thinking now it's jQuery that's causing the issue, based on that previous answer (I'm not that familiar with JQuery myself, so I can't be 100% sure)
Tim Goodman
Yep, you're right. I rewrote the code to use native DOM methods, and the case is now respected. I resisted jQuery until recently, and pretty much love it. I must admit I feel a little smug to know better once in a while.
harpo
That's your good karma paying off from learning the non-JQuery way first. :)
Tim Goodman