In the result of an AJAX call I have multiple fields in XML format. One of the nodes called Request contains an entire XML structure that I want to display.
var request = $(xml).find("Request").html()
The above line returns me the content of the Request node. However, one of the tags is called <INPUT>. Which is ofcourse being interpreted as an HTML-element.
This is the result I get in my var request :
<root>
<input>
<i_date>20150316</i_date>
<i_order_nr>110535</i_order_nr>
<i_sequence_number>0057</i_sequence_number>
<i_time>105016</i_time>
<i_uom>KG</i_uom>
</root>
As you can see the closing </input> tag is missing. It is present in the response of my Ajax call. But by using JQuery .html() it is removed. How can I get the content of the Request node without Jquery interpretting the tags?
$(xml).find("Request").html().replace(/input/g , "input2"), so you get an<input2></input2>tag or something, which won't get interpreted. Comes with no warranties..html()but with$(xml)itself. And it is time to use hacks like replacing<input>with<input2>or to use another technologies for parsing.<input>String, not justinput. 2. It has to be done in the original string before$(xml)is executed.xmlis a string, do a regex before doing$(xml)to replace all<input>, something likexml.replace(/<input\s+?([^>]+)?>/gi, '<item $1>')- untested.textinstead of.html, if you want to get it parsed by the browser (it's odd because it's not HTML) you shouldn't fix it in client side, it's in invalid HTML, you should fix it at your source.