我需要从 XML 文件中读取数据。 这是 XML 文件中的数据。
<?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>
在指定的示例中,我想验证/读取 coverflowconfig 值。即 行项目之间的空间, 投影 Angular 投影 Angular 。
最佳答案
我希望这不是准确的 XML,因为它无效。但忘记了...假设它有效,您可以使用 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);
关于javascript - 如何使用 JavaScript 解析附加的 XML 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23571051/