Reputation: 2005
Is it possible to add xml data in a html document?
like
<xml>
<fruits>
<apple color="red" />
<peach color="link" />
</fruits>
</xml>
and access it with jQuery?
Upvotes: 0
Views: 48
Reputation: 163625
You miight find this helpful:
http://norman.walsh.name/2011/03/26/HTML-XML-Prague
The basic answer is that the best you can probably do is to put your XML in a script element - but that won't make it accessible via the HTML DOM.
Upvotes: 1
Reputation: 1777
I don't know why do you want to add the xml data in the HTML page.
If you just want to display it, you can simply put it in the textarea. If you want to manipulate the data of xml, you can translate it to a javascript array or a json object, such as:
var fruits = {
apple: red,
peach: link
}
Upvotes: 2
Reputation: 71961
not to be blunt, but did you try it?
And yes, it is possible, and no it will not be html5 valid
console.log($('apple').attr('color'));
will output 'red'
Upvotes: 0