I am doing json_encode(simplexml_load_file($xmlpath))
I am getting the output as below.
{"@attributes":{
"source":"Tas Football",
"version":"4.14.00",
"generated":"8\/20\/2013"
},
"venue":{
"@attributes":{
"visname":"Book"
}
}
}
I am using this json in javascript and storing it in data
variable
I am trying to access the elements but not getting any success.
alert(data.venue.@attributes.visname);
The above code doesn't show any output.
The ajax code for this is below:
$.get("fetchXml.php?file=../../xml/wk1/BookerTWashington_Douglas.xml",function (data){
data=$.parseJSON(data);
alert(data.venue.@attributes.visname);
});
The @ in the variable name is invalid: JavaScript is a case-sensitive language. This means that a variable name such as myCounter is different from the variable name MYCounter. Variable names can be of any length. The rules for creating legal variable names are as follows:
The first character must be an ASCII letter (either uppercase or lowercase), or an underscore (_) character. Note that a number cannot be used as the first character.
Subsequent characters must be letters, numbers, or underscores (_).
The variable name must not be a reserved word. http://msdn.microsoft.com/en-us/library/ie/67defydd(v=vs.94).aspx
Try this:
data.venue['@attributes'].visname