XML Parse Error



I have this jquery code that takes an xml variable parse it and display it in a html file, and it works as supposed. The problem is once I try to take the xml variable from a php script and give this varibale as an input of the above jquery script I get an error message in my web browser.


My script:



<?php
require('MyClass.php');
$Myparam = "0123641";
$built_request=new MyClass($Myparam);
$xml=$built_request->getResponse();// works fine and returns an xml variable represented as below
?>
<html lang="en">
<head>
<meta charset="utf-8"></meta>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<BODY>
<p id="someElement"></p>
<script>
$(document).ready(function(){
var xml ="<?php echo $xml; ?>";
var d1 = $(xml).find('data[name="name2"]').attr('status');
$( "#someElement" ).append( d1 );
});
</script>
</BODY>
</html>


This is the obtained error in the web browser despite when I give this same xml variable direct in the javascript, the script works.



XML Parse Error: XML or text declaration not at start of entity
var xml ="<?xml version="1.0" encoding="UTF-8"?>
--------------^


Trying to investigate this problem I printed my obtained variable and the printed value is as following:



<?xml version="1.0" encoding="UTF-8"?>
<data request-id="31236">
<data name="name1" code="0" code2="003404502" code3="">
<data name="name2" code1="34297502" -time="2014-09-01" -id="14c259b-bsdfgds8b5"leitcode="" code2="692748" order="false" piece-code="00363932" piece-status="0"identifier-type="2" pan-recipient-name="" street-name="" house-number="" city-name="" status="status x" error-status="0" code_name="code name" />
</data>
</data>

No comments:

Post a Comment