Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitivity in selectors?

Tags:

jquery

xml

case

I am trying to use jQuery for XML processing. One of the problem that I am stuck with jQuery is it is case insensitive in processing tags and attribute.

For e.g., consider the following code:

$("<div><Book ISBN='1234'>Some title</Book></div>").html()

the output we get is:

<book isbn="1234">Some title</book>

whereas the output i am looking for is:

<Book ISBN="1234">Some title</Book>

Any possibility? (Note that "B" is capital letter, and the whole attribute name "ISBN" is also in capital case, whereas the jQuery html output is completely lower case) Please help.

like image 910
Srikanth Vittal Avatar asked Apr 26 '11 14:04

Srikanth Vittal


2 Answers

According to http://www.w3.org/TR/CSS21/selector.html, in HTML element names are case-insensitive, but in XML they are case- sensitive. The same is true for attribute names.

So, the HTML output you are getting is correct. To my knowledge, jQuery core can't create an HTML document, where case sensitivity matters for element and attribute names.

EDIT: See below. I had originally said jQuery can't create an XML document where case sensitivity matters. Clearly, it can. But it can't preserve the case if you're injecting into HTML. For a solution, see: jQuery converting XML tags to uppercase

like image 158
two7s_clash Avatar answered Oct 24 '22 22:10

two7s_clash


the problem would be the .html() ... html in itself should be lowercase so jquery jsut return the "Valid" html format. if u need to parse xml i am sure theres librairy to do it that will keep the Case of your Xml.

personally i would try parsexml or any of the library you could find with a quick search

http://api.jquery.com/jQuery.parseXML/

like image 1
Lil'Monkey Avatar answered Oct 24 '22 20:10

Lil'Monkey