# Python: module fabmetheus_utilities.xml_simple_reader

fabmetheus_utilities.xml_simple_reader ($Date: 2008/21/04 $) | index /home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/fabmetheus_utilities/xml_simple_reader.py

`The xml_simple_reader.py script is an xml parser that can parse a line separated xml text.
This xml parser will read a line seperated xml text and produce a tree of the xml with a document element. Each element can have an attribute table, childNodes, a class name, parentNode, text and a link to the document element.
This example gets an xml tree for the xml file boolean.xml. This example is run in a terminal in the folder which contains boolean.xml and xml_simple_reader.py.
> python
Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fileName = 'boolean.xml'
>>> file = open(fileName, 'r')
>>> xmlText = file.read()
>>> file.close()
>>> from xml_simple_reader import DocumentNode
>>> xmlParser = DocumentNode(fileName, xmlText)
>>> print(xmlParser)
?xml, {'version': '1.0'}
ArtOfIllusion, {'xmlns:bf': '//babelfiche/codec', 'version': '2.0', 'fileversion': '3'}
Scene, {'bf:id': 'theScene'}
materials, {'bf:elem-type': 'java.lang.Object', 'bf:list': 'collection', 'bf:id': '1', 'bf:type': 'java.util.Vector'}
..
many more lines of the xml tree
..`

Modules

``

__init__ fabmetheus_utilities.archive | cStringIO fabmetheus_utilities.euclidean | fabmetheus_utilities.geometry.geometry_utilities.evaluate fabmetheus_utilities.geometry.geometry_utilities.matrix | fabmetheus_utilities.xml_simple_writer

Classes

``

CDATASectionMonad
  CommentMonad
  DocumentTypeMonad
CDATASectionNode
  CommentNode
  DocumentTypeNode
  TextNode
DocumentNode
ElementEndMonad
  OpenChooseMonad
  OpenMonad
ElementLocalNameMonad
ElementNode
ElementReadMonad
KeyMonad
TextMonad
ValueMonad

class CDATASectionMonad
`` | `A monad to handle a CDATASection node.`

Methods defined here:

__init__(self, input, parentNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

class CDATASectionNode
`` | `A CDATASection node.`

Methods defined here:

__init__(self, parentNode, textContent='')
  `Initialize.`

__repr__(self)
  `Get the string representation of this CDATASection node.`

addToIdentifierDictionaries(self)
  `Add the element to the owner document identifier dictionaries.`

addXML(self, depth, output)
  `Add xml for this CDATASection node.`

appendSelfToParent(self)
  `Append self to the parentNode.`

copyXMLChildNodes(self, idSuffix, parentNode)
  `Copy the xml childNodes.`

getAttributes(self)
  `Get the attributes.`

getChildNodes(self)
  `Get the empty set.`

getCopy(self, idSuffix, parentNode)
  `Copy the xml element, set its dictionary and add it to the parentNode.`

getCopyShallow(self, attributes=None)
  `Copy the node and set its parentNode.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

getOwnerDocument(self)
  `Get the owner document.`

getTextContent(self)
  `Get the text content.`

removeChildNodesFromIDNameParent(self)
  `Remove the childNodes from the id and name dictionaries and the childNodes.`

removeFromIDNameParent(self)
  `Remove this from the id and name dictionaries and the childNodes of the parentNode.`

setParentAddToChildNodes(self, parentNode)
  `Set the parentNode and add this to its childNodes.`

Data descriptors defined here:

attributes
  `Get the attributes.`

childNodes
  `Get the empty set.`

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

ownerDocument
  `Get the owner document.`

class CommentMonad(CDATASectionMonad)
`` | `A monad to handle a comment node.`

Methods defined here:

getNextMonad(self, character)
  `Get the next monad.`

Methods inherited from CDATASectionMonad:

__init__(self, input, parentNode)
  `Initialize.`

class CommentNode(CDATASectionNode)
`` | `A comment node.`

Methods defined here:

getCopyShallow(self, attributes=None)
  `Copy the node and set its parentNode.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

Data descriptors defined here:

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

Methods inherited from CDATASectionNode:

__init__(self, parentNode, textContent='')
  `Initialize.`

__repr__(self)
  `Get the string representation of this CDATASection node.`

addToIdentifierDictionaries(self)
  `Add the element to the owner document identifier dictionaries.`

addXML(self, depth, output)
  `Add xml for this CDATASection node.`

appendSelfToParent(self)
  `Append self to the parentNode.`

copyXMLChildNodes(self, idSuffix, parentNode)
  `Copy the xml childNodes.`

getAttributes(self)
  `Get the attributes.`

getChildNodes(self)
  `Get the empty set.`

getCopy(self, idSuffix, parentNode)
  `Copy the xml element, set its dictionary and add it to the parentNode.`

getOwnerDocument(self)
  `Get the owner document.`

getTextContent(self)
  `Get the text content.`

removeChildNodesFromIDNameParent(self)
  `Remove the childNodes from the id and name dictionaries and the childNodes.`

removeFromIDNameParent(self)
  `Remove this from the id and name dictionaries and the childNodes of the parentNode.`

setParentAddToChildNodes(self, parentNode)
  `Set the parentNode and add this to its childNodes.`

Data descriptors inherited from CDATASectionNode:

attributes
  `Get the attributes.`

childNodes
  `Get the empty set.`

ownerDocument
  `Get the owner document.`

class DocumentNode
`` | `A class to parse an xml text and store the elements.`

Methods defined here:

__init__(self, fileName, xmlText)
  `Initialize.`

__repr__(self)
  `Get the string representation of this xml document.`

appendChild(self, elementNode)
  `Append child elementNode to the child nodes.`

getAttributes(self)
  `Get the attributes.`

getCascadeBoolean(self, defaultBoolean, key)
  `Get the cascade boolean.`

getCascadeFloat(self, defaultFloat, key)
  `Get the cascade float.`

getDocumentElement(self)
  `Get the document element.`

getElementsByLocalName(self, localName)
  `Get the descendents which have the given local name.`

getImportNameChain(self, suffix='')
  `Get the import name chain with the suffix at the end.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

getOriginalRoot(self)
  `Get the original reparsed document element.`

getOwnerDocument(self)
  `Get the owner document.`

Data descriptors defined here:

attributes
  `Get the attributes.`

documentElement
  `Get the document element.`

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

ownerDocument
  `Get the owner document.`

class DocumentTypeMonad(CDATASectionMonad)
`` | `A monad to handle a document type node.`

Methods defined here:

getNextMonad(self, character)
  `Get the next monad.`

Methods inherited from CDATASectionMonad:

__init__(self, input, parentNode)
  `Initialize.`

class DocumentTypeNode(CDATASectionNode)
`` | `A document type node.`

Methods defined here:

getCopyShallow(self, attributes=None)
  `Copy the node and set its parentNode.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

Data descriptors defined here:

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

Methods inherited from CDATASectionNode:

__init__(self, parentNode, textContent='')
  `Initialize.`

__repr__(self)
  `Get the string representation of this CDATASection node.`

addToIdentifierDictionaries(self)
  `Add the element to the owner document identifier dictionaries.`

addXML(self, depth, output)
  `Add xml for this CDATASection node.`

appendSelfToParent(self)
  `Append self to the parentNode.`

copyXMLChildNodes(self, idSuffix, parentNode)
  `Copy the xml childNodes.`

getAttributes(self)
  `Get the attributes.`

getChildNodes(self)
  `Get the empty set.`

getCopy(self, idSuffix, parentNode)
  `Copy the xml element, set its dictionary and add it to the parentNode.`

getOwnerDocument(self)
  `Get the owner document.`

getTextContent(self)
  `Get the text content.`

removeChildNodesFromIDNameParent(self)
  `Remove the childNodes from the id and name dictionaries and the childNodes.`

removeFromIDNameParent(self)
  `Remove this from the id and name dictionaries and the childNodes of the parentNode.`

setParentAddToChildNodes(self, parentNode)
  `Set the parentNode and add this to its childNodes.`

Data descriptors inherited from CDATASectionNode:

attributes
  `Get the attributes.`

childNodes
  `Get the empty set.`

ownerDocument
  `Get the owner document.`

class ElementEndMonad
`` | `A monad to look for the end of an ElementNode tag.`

Methods defined here:

__init__(self, parentNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

class ElementLocalNameMonad
`` | `A monad to set the local name of an ElementNode.`

Methods defined here:

__init__(self, character, parentNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

setLocalName(self)
  `Set the class name.`

class ElementNode
`` | `An xml element.`

Methods defined here:

__init__(self, parentNode=None)
  `Initialize.`

__repr__(self)
  `Get the string representation of this xml document.`

addSuffixToID(self, idSuffix)
  `Add the suffix to the id.`

addToIdentifierDictionaries(self)
  `Add the element to the owner document identifier dictionaries.`

addXML(self, depth, output)
  `Add xml for this elementNode.`

appendChild(self, elementNode)
  `Append child elementNode to the child nodes.`

appendSelfToParent(self)
  `Append self to the parentNode.`

copyXMLChildNodes(self, idSuffix, parentNode)
  `Copy the xml childNodes.`

getCascadeBoolean(self, defaultBoolean, key)
  `Get the cascade boolean.`

getCascadeFloat(self, defaultFloat, key)
  `Get the cascade float.`

getChildElementsByLocalName(self, localName)
  `Get the childNodes which have the given local name.`

getCopy(self, idSuffix, parentNode)
  `Copy the xml element, set its dictionary and add it to the parentNode.`

getCopyShallow(self, attributes=None)
  `Copy the xml element and set its dictionary and parentNode.`

getDocumentElement(self)
  `Get the document element.`

getElementNodeByID(self, idKey)
  `Get the xml element by id.`

getElementNodesByName(self, nameKey)
  `Get the xml elements by name.`

getElementNodesByTag(self, tagKey)
  `Get the xml elements by tag.`

getElementsByLocalName(self, localName)
  `Get the descendents which have the given local name.`

getFirstChildByLocalName(self, localName)
  `Get the first childNode which has the given class name.`

getIDSuffix(self, elementIndex=None)
  `Get the id suffix from the dictionary.`

getImportNameChain(self, suffix='')
  `Get the import name chain with the suffix at the end.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

getOwnerDocument(self)
  `Get the owner document.`

getParser(self)
  `Get the parser.`

getPaths(self)
  `Get all paths.`

getPreviousElementNode(self)
  `Get previous ElementNode if it exists.`

getPreviousVertex(self, defaultVector3=None)
  `Get previous vertex if it exists.`

getStrippedAttributesValue(self, keyString)
  `Get the stripped attribute value if the length is at least one, otherwise return None.`

getSubChildWithID(self, idReference)
  `Get the childNode which has the idReference.`

getTagKeys(self)
  `Get stripped tag keys.`

getTextContent(self)
  `Get the text from the child nodes.`

getValueByKey(self, key)
  `Get value by the key.`

getVertexes(self)
  `Get the vertexes.`

getXMLProcessor(self)
  `Get the xmlProcessor.`

linkObject(self, xmlObject)
  `Link self to xmlObject and add xmlObject to archivableObjects.`

printAllVariables(self)
  `Print all variables.`

printAllVariablesRoot(self)
  `Print all variables and the document element variables.`

removeChildNodesFromIDNameParent(self)
  `Remove the childNodes from the id and name dictionaries and the childNodes.`

removeFromIDNameParent(self)
  `Remove this from the id and name dictionaries and the childNodes of the parentNode.`

setParentAddToChildNodes(self, parentNode)
  `Set the parentNode and add this to its childNodes.`

setTextContent(self, textContent='')
  `Get the text from the child nodes.`

Data descriptors defined here:

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

ownerDocument
  `Get the owner document.`

textContent
  `Get the text from the child nodes.`

class ElementReadMonad
`` | `A monad to read the attributes of the ElementNode tag.`

Methods defined here:

__init__(self, elementNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

class KeyMonad
`` | `A monad to set the key of an attribute of an ElementNode.`

Methods defined here:

__init__(self, character, elementNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

class OpenChooseMonad(ElementEndMonad)
`` | `A monad to choose the next monad.`

Methods defined here:

getNextMonad(self, character)
  `Get the next monad.`

Methods inherited from ElementEndMonad:

__init__(self, parentNode)
  `Initialize.`

class OpenMonad(ElementEndMonad)
`` | `A monad to handle the open tag character.`

Methods defined here:

getNextMonad(self, character)
  `Get the next monad.`

Methods inherited from ElementEndMonad:

__init__(self, parentNode)
  `Initialize.`

class TextMonad
`` | `A monad to handle the open tag character and set the text.`

Methods defined here:

__init__(self, parentNode)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

class TextNode(CDATASectionNode)
`` | `A text node.`

Methods defined here:

addXML(self, depth, output)
  `Add xml for this text node.`

getCopyShallow(self, attributes=None)
  `Copy the node and set its parentNode.`

getNodeName(self)
  `Get the node name.`

getNodeType(self)
  `Get the node type.`

Data descriptors defined here:

nodeName
  `Get the node name.`

nodeType
  `Get the node type.`

Methods inherited from CDATASectionNode:

__init__(self, parentNode, textContent='')
  `Initialize.`

__repr__(self)
  `Get the string representation of this CDATASection node.`

addToIdentifierDictionaries(self)
  `Add the element to the owner document identifier dictionaries.`

appendSelfToParent(self)
  `Append self to the parentNode.`

copyXMLChildNodes(self, idSuffix, parentNode)
  `Copy the xml childNodes.`

getAttributes(self)
  `Get the attributes.`

getChildNodes(self)
  `Get the empty set.`

getCopy(self, idSuffix, parentNode)
  `Copy the xml element, set its dictionary and add it to the parentNode.`

getOwnerDocument(self)
  `Get the owner document.`

getTextContent(self)
  `Get the text content.`

removeChildNodesFromIDNameParent(self)
  `Remove the childNodes from the id and name dictionaries and the childNodes.`

removeFromIDNameParent(self)
  `Remove this from the id and name dictionaries and the childNodes of the parentNode.`

setParentAddToChildNodes(self, parentNode)
  `Set the parentNode and add this to its childNodes.`

Data descriptors inherited from CDATASectionNode:

attributes
  `Get the attributes.`

childNodes
  `Get the empty set.`

ownerDocument
  `Get the owner document.`

class ValueMonad
`` | `A monad to set the value of an attribute of an ElementNode.`

Methods defined here:

__init__(self, elementNode, key)
  `Initialize.`

getNextMonad(self, character)
  `Get the next monad.`

Functions

``

createAppendByText(parentNode, xmlText)
  `Create and append the child nodes from the xmlText.`

createAppendByTextb(parentNode, xmlText)
  `Create and append the child nodes from the xmlText.`

getChildElementsByLocalName(childNodes, localName)
  `Get the childNodes which have the given local name.`

getDocumentNode(fileName)
  `Get the document from the file name.`

getElementsByLocalName(childNodes, localName)
  `Get the descendents which have the given local name.`

getFileText(fileName, printWarning=True, readMode='r')
  `Get the entire text of a file.`

Data

``

__author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
__credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>'
__date__ = '$Date: 2008/21/04 $'
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
absolute_import = _Feature((2, 5, 0, 'alpha', 1), (2, 7, 0, 'alpha', 0), 16384)
globalGetAccessibleAttributeSet = set(['getPaths', 'getPreviousElementNode', 'getPreviousVertex', 'getVertexes', 'parentNode'])

Author
`` |  | Enrique Perez (perez_enrique@yahoo.com)

Credits
`` |  | Nophead <http://hydraraptor.blogspot.com/> Art of Illusion <http://www.artofillusion.org/>