Next Step: Show the Document Element's Attributes
<<<< ^^^^^ >>>>

Add import string, sub asciiNodeType(), sub printNodeInfo(), and call printNodeInfo().

from xml.dom.ext.reader.Sax import FromXmlFile
from xml.dom import Node,Element,Document,Text
import sys
import string

def asciiNodeType(n):

def printNodeInfo(mynode):
   print asciiNodeType(mynode._get_nodeType()) + ' :',
   print mynode._get_nodeName() + ' :',
   print mynode._get_nodeValue(),
   if __textType == 'ELEMENT':
      __attrList = mynode.attributes;
      print '(', 
      for __ss in range(0, __attrList._get_length()):
         __attrName = __attrList.keys()[__ss];
         __attrValue = mynode.getAttribute(__attrName);
         print __attrName + '="' + __attrValue + '"',
      print ') ', 
   print '.'

__domObject = FromXmlFile(sys.argv[1])
print __domObject.documentElement

<<<< ^^^^^ >>>>
Copyright (C) 2000 by Steve Litt, you can freely distribute unmodified copies if this copyright notice and disclaimer are intact.  This material originally appeared on Troubleshooters.Com.

This presentation has no warrantee, express or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the presentation is with you.


Exit Slideshow