This will get the proper root/text value. The text can be placed everywhere in the root node.
<script type="text/javascript">
$().ready(function() {
var xml = $('#xml').find('root').contents().each(function(i){
if (this.nodeName=="#text" && this.nodeType=="3" && this.nodeValue.length>2) alert(this.nodeValue);
});
});
</script>
for:
<div id="xml"><root><item1>text1</item1><item2>text2</item2>more text here</root></div>
Note: "inline" xml is not working in Internet Explorer, but if you replace root and itemX in the example with valid Html nodenames, it will work too.
Explanation: DOM treats empty and text nodes as Elements. if you debug the above .each(), you'll see the following:
alert( this.nodeName + '|' + this.nodeType + "|" + this.nodeValue);
#text|3| , ITEM1|1|null , #text|3| , ITEM2|1|null , #text|3| more text here
(Sorry, formatting is not working with a Hungarian keyboard, still)