I have the following code :
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p id="someElement"></p>
<p id="anotherElement"></p>
<script>
var xml = "<count>1</count><ticketID id='2'><incidentUrl>3</incidentUrl></ticketID>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "count" );
/* append "RSS Title" to #someElement */
$( "#someElement" ).append( $title.text() );
/* change the title to "XML Title" */
$title.text( "XML Title" );
/* append "XML Title" to #anotherElement */
$( "#anotherElement" ).append( $title.text() );
</script>
</body>
</html>
The above code – produces an error : Invalid XML
However , when i change var xml to :
var xml = < count >1< / count >
it works without any errors.
Why is this ?
Thanks!
You cannot have two root elements in an XML document.
Note that according to the official syntax there can be only one “top-level” or “root” element.
Your example has both count and ticketId at the top-level, which is not allowed.