Package zephir :: Package monitor :: Module xmlite
[frames] | no frames]

Module xmlite

source code

Copyright (C) 2003 Peter Ohler

XMLite is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

XMLite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You download a copy of the GNU General Public License at http://www.gnu.org/licenses/gpl.txt or obtain a copy of the GNU General Public License by writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

XMLite - extremely light weight XML parse and printer

The xmlite module is an extremely light weight XML parser and printer. It does not use the DOM or SAX interfaces but instead works with a simple list or rather nested lists to represent an XML document. The parser takes as input a string or filename and returns a list with all the elements of the XML file.

The first item in the top level XML list is a dict object with 'version', 'encoding', and 'standalone' keys. If there are any decl tags such as 'DOCTYPE' they will be next in the list and will be tuples with the decl tag name and the value of the tag as the second item of the tuple.

Comments are included as lists of two items. The first item is None and the second is a string which is the comment text.

CDATA are tuples of two items. The first item is 'CDATA' and the second is the CDATA content.

XML elements are lists. The first item in the list is the element tag or name. The second item is a dict object with includes all the attributes of the element. Any remainin list items are either comments, strings, CDATA, or more elements as lists.

Author: Peter Ohler, peter@ohler.com $Id: xmlite.py,v 1.1.1.1 2004/05/12 09:26:11 sam Exp $

Classes
  XmlException
XML Exception for reporting errors in parsing of an XML file or string.
Functions
 
printXml(xml, indent=0)
Print out a list that matches the expected XML list format.
source code
 
printAttrs(attrs, indent) source code
 
toStr(xml, s="", indent=0)
Return a string that is an XML document.
source code
 
attrsToStr(attrs, s, indent) source code
 
load(filename)
Load complete file into memory and then parse the string.
source code
 
parse(s)
Make one pass and parse directly into an XML list.
source code
 
readProlog(s, i, x) source code
 
readNameToken(s, i) source code
 
readQuotedValue(s, i) source code
 
readComment(s, i, x) source code
 
readDecl(s, i, x) source code
 
readElement(s, i, x) source code
 
readCData(s, i, x) source code
 
readText(s, i, x) source code
 
replaceCodedChars(text) source code
 
readCodedChar(s, i) source code
 
expandCodedChars(s) source code
Variables
  nonNameStr = " \t\n\r?=/><\x0b\x0c"
Function Details

printXml(xml, indent=0)

source code 
Print out a list that matches the expected XML list format. Other formats may not print out correctly. The output format is XML.