Can we maintain an XML data structure on the client side using JavaScript? Is there any parser to parse the xml data on the client side? The xml data will be passed as an string.

Nicola Ken Barozzi

Yes, refer to the XML data islands on the Microsoft web site.
You can have the XML in a web page (which can be generated dynamically) or embedded in the HTML. You can use Microsoft XML data islands that get XML data from a servlet.
CODE:


<HTML>

  <SCRIPT>
    function display()
    {
      data.transformNodeToObject(ss.XMLDocument, resultTree.XMLDocument);
      document.write(resultTree.xml);
    }
       </SCRIPT>
  
  <SCRIPT FOR="window" EVENT="onload">
    data.async = false;
    data.load("../servlet/SQLResult");
    ss.async = false;
    ss.load("MyStyleSheet.xsl");
    display();
  </SCRIPT>
  
  <XML id="data"></XML>
  <XML id="ss"></XML>
  <XML id="resultTree"></XML>


</HTML>

Here "../servlet/SQLResult" is a servlet URL.

If you prefer you can embed the XML directly in the page.
CODE:

<HTML>

  <SCRIPT>
    function display()
    {
      data.transformNodeToObject(ss.XMLDocument, resultTree.XMLDocument);
      document.write(resultTree.xml);
    }
       </SCRIPT>
  
  <SCRIPT FOR="window" EVENT="onload">
    data.async = false;
    ss.async = false;
    ss.load("MyStyleSheet.xsl");
    display();
  </SCRIPT>
  
  <XML id="data"></XML>
  <XML id="ss"></XML>
  <XML id="resultTree">

  YOUR XML GOES HERE
 
  </XML>


</HTML>

Also refer to jGuru FAQ Entry 39154.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.