使用JQuery将XML数据加载到div中

时间:2014-03-11 11:47:10

标签: jquery xml

我有以下xml内容格式,想知道我是否可以使用JQuery将数据加载到div中:

<?xml version="1.0" encoding="ISO-8859-15"?>
<status>
  <client pid="239" account="account1" host="domaina.com" />
  <client pid="459" account="account2" host="domainb.com" />
  <client pid="235" account="account3" host="domainc.com" />
</status>

我见过的大多数xml示例都采用以下格式:

<?xml version="1.0" encoding="utf-8" ?>
<Status>
  <client>
     <pid>239</pid>
     <account>account1</account>
     <host>domaina.com</host>
  </client>
  <client>
     <pid>459</pid>
     <account>account2</account>
     <host>domainb.com</host>
  </client>
  <client>
     <pid>235</pid>
     <account>account3</account>
     <host>domainc.com</host>
  </client>
</Status>

我是否可以使用指南在第一个xml文件中加载数据,或者为我提供可能重复问题的链接。

由于

2 个答案:

答案 0 :(得分:0)

您可以使用jquery库来解析您的xml数据以供参考,您可以访问jquery站点     https://api.jquery.com/jQuery.parseXML/

How to parse XML using jQuery?

答案 1 :(得分:0)

有一个方便的 JQuery插件可以将简单的XML转换为JSON对象http://www.fyneworks.com/jquery/xml-to-json/#tab-Usage。你可以这样做:

var xml = '<status><client pid="239" account="account1" host="domaina.com" />
           <client pid="459" account="account2" host="domainb.com" />
           <client pid="235" account="account3" host="domainc.com" /></status>';

$.getScript('http://jquery-xml2json-plugin.googlecode.com/svn/trunk/jquery.xml2json.js');

$.xml2json(xml);
相关问题