0

I have a requirement to read data from the XML file. Here is the data in XML file.

<?xml version="1.0"?>
<application id="AndroidCoverFlow" name="AndroidCoverFlow" platform="general">
       <attributes datatype="ref" value="{"coverflowConfig":{"spaceBetweenRowItems":5,"projectionAngle":90,"isCircular":true,"rowItemWidth":5,"rowItemRotationAngle":180}}" name="viewConfig" platform="general" buckettype="basic"/>
       </application>

in the specified example, I want to verify/Read the coverflowconfig values.i.e spaceBetweenRowItems, projectionAngle projectionAngle.

4
  • 3
    This isn't valid XML. You have double quotes inside double quotes in your value. Is this what it really looks like? Commented May 9, 2014 at 17:56
  • 1
    It looks like you have JSON in your XML... Commented May 9, 2014 at 17:57
  • Are u shure is it: value="{" and not: value="{' Commented May 9, 2014 at 18:12
  • I am sure,the attached snippet is correct one.This is generated from some javascript code through IDE.i have copied some content from the whole xml file. Commented May 9, 2014 at 18:25

2 Answers 2

1

I hope this isn't the exact XML, because it's not valid. But forgetting that... assuming it is valid, you can parse it using DOMParser.

var parser = new DOMParser,
    xmlDom = parser.parseFromString(xml, 'text/xml');

var application = xmlDom.getElementById('AndroidCoverFlow'),
    attributes = application.getElementsByTagName('attributes');

var value = attributes[0].attributes.getNamedItem('value').value,
    jsonData = JSON.parse(value);

console.dir(jsonData);

DEMO: http://jsbin.com/soxobuba/2/edit?js,console

Sign up to request clarification or add additional context in comments.

Comments

0

Fiddle: http://jsfiddle.net/abdennour/MUws7/

NOTE:

It is not an XML code, You could check it By : http://www.w3schools.com/xml/xml_validator.asp

However , if it is an XML Code , You can use a Javascript library such as jQuery, then do this :

$(xml).find("attributes").each(function()
  {
   var myObject=$(this).attr("value")
   $("#output").html(myObject);
       myObject=myObject.replaceAll("'",'"')
      alert(myObject)
      coverflowConfig=$.parseJSON(myObject).coverflowConfig;
      alert('coverflowConfig.projectionAngle='+coverflowConfig.projectionAngle)


  });

Fiddle: http://jsfiddle.net/abdennour/MUws7/

3 Comments

The question doesn't say that he's using jQuery.
jquery = is a JS library
Yeah. I'm well aware what jQuery is. The person asking the question the didn't indicate that they are using it. So, you might wanna mention that this uses the jQuery library in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.