0

I have the following xml content format and would like to know if I can use JQuery to load the data into 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>

Most xml examples I have seen are in this format:

<?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>

Is there a guide I can follow to load data in the first xml file or provide me with links to possibly duplicate question.

Thanks

Chelseawillrecover
  • 2,596
  • 1
  • 31
  • 51

3 Answers3

0

you can user jquery libraries to parse your xml data for reference you can visit the jquery site https://api.jquery.com/jQuery.parseXML/ also

How to parse XML using jQuery?

Community
  • 1
  • 1
Divya
  • 1,469
  • 1
  • 13
  • 25
0

I was doing this recently, but I ended up using a TextArea as it was able to keep the indentation/etc.. there are plugins for Div's but it'll most likely need to be escaped to be shown properly wihtout it.. best link I can provide is : http://www.w3schools.com/xml/xml_to_html.asp

    <html>
    <body>

    <script>
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.open("GET","cd_catalog.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML; 

    document.write("<table border='1'>");
    var x=xmlDoc.getElementsByTagName("CD");
    for (i=0;i<x.length;i++)
      { 
      document.write("<tr><td>");
      document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
      document.write("</td></tr>");
      }
    document.write("</table>");
    </script>

    </body>
    </html>

cant find the plugin but it was for showing code also.. might be able to get it with a bit of digging and ill update.

JF it
  • 2,403
  • 3
  • 20
  • 30
0

There's a handy JQuery plugin to convert simple XML into a JSON object http://www.fyneworks.com/jquery/xml-to-json/#tab-Usage. You can do something like this:

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);
Ermias
  • 33
  • 6