0

I am using jQuery object to append elements and modify the values of an XML document, which I am initializing using a XML string which has nodes such as <tgroup>, <table>, <row>, <tbody>, etc. as seen below.

var str = "<txml> <table><tsnipp><tbody> <row> ... </row>  </tbody> </tsnipp> </table> </txml>"

Now I am creating a jQuery object using $(str). The <tsnipp> element in the XML document is under the <table> element; however, when inspecting the jQuery object using Firebug, I see it as above the <table> element, and thus the <tsnipp> is at the same level as the <table>, as opposed to being one of its children. I think jQuery itself organizes it that way because it thinks the <table> element is an HTML element.

By just changing <table> to <d_table>, jQuery does the right thing.

I wanted to use jQuery to manipulate the object as it is easier to manipulate as a DOM object. However, converting it into a string and then to a jQuery object will require a lot of regular expressions to replace certain strings into others, back and forth.

Ry-
  • 218,210
  • 55
  • 464
  • 476
user593029
  • 511
  • 7
  • 18

1 Answers1

0

You can use jQuery.parseXML to parse the document as XML instead of HTML:

var doc = $($.parseXML(str));
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • 1
    Yes it works.. If someone is looking for how to parse use this code: var serl = new XMLSerializer(doc) var txt = serl.serializeToString(doc); – user593029 Jul 18 '12 at 20:48