mozdev.org

Xanthes  

Home | Mailing List | Download | Source Code | Bugs | Documentation

Javascript Example

This example loads a remote xml file into a DOM document and then outputs the raw xml to a text field.

<html>
    <head>
        <script>    
        function loadTest()
        {     
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        var DOMParser = Components.classes["@xerces.mozdev.org/x_domparser;1"].createInstance();
        var DOMParser = DOMParser.QueryInterface(Components.interfaces.xIDOMParser);
        var xmldocument = DOMParser.parse("http://xerces.mozdev.org/dload/test.xml", 0)

        // QI to get the node interface
        var node = xmldocument.QueryInterface(Components.interfaces.xINode)
        var field = document.getElementById('txtRawXML');
      
	// Grab the raw xml
        field.value = node.xml;
        }
      
        </script>
        <title></title>
    </head>
    <body>
        <p>Some text here       
        <input type="button" value="Load test.xml" name="BLoadTest" onclick="loadTest();">
        <p>
        <textarea rows="20" id="txtRawXML" name="txtRawXML" cols="80"></textarea>
    </body>
</html>

Python Example

The following code demonstrates traversing an xml document from python.

import xpcom
import string
from xpcom import components

def traverse(node):
    node = node.QueryInterface(components.interfaces.xINode) 
    type = node.nodeType
    name = node.nodeName
    print name  
    children = node.childNodes
    if (children ):
        for i in range( children.length):
            traverse(children.item(i))      

cls = xpcom.components.classes["@xerces.mozdev.org/x_domparser;1"]  
obj = cls.createInstance(components.interfaces.xIDOMParser)
document = obj.parse("file:\\dev\\moz_src\\mozilla\\xercesxpcom\\samples\\test.xml", 0)     
traverse(document) )
  

The xanthes project can be contacted through the mailing list or the member list.
Copyright © 2000-2009. All rights reserved. Terms of Use & Privacy Policy.