Package dsc_suite :: Package gui :: Module xmlpars :: Class XMLParser
[hide private]
[frames] | no frames]

Class XMLParser

source code

object --+
         |
        XMLParser

class XMLParser(object) This class is the parser for the XML files. It is based on dictionary interface to the GUI. Every key in a dictionary is used as a tag name in the XML file. The value is either the tag content or (when a dictionary) the next hierarchical level of the XML file.

Instance Methods [hide private]
 
__init__(self, source, mode)
__init__
source code
 
nextTopLevelTag(index)
returns a dictionary with: key ...
source code
 
countTopLevelTags()
returns number of toplevel items in XML file
source code
 
writeNewData(dict)
- writes the data from dict into the XML File - Attention: XML File must exist and have a root instance.
source code
 
createNewXML(path, string)
creates a new XMl file with the given path an adds the root instance named by string
source code
 
getRootName()
return the name of the root instance in the XML file
source code
 
getCharacteristic(data, algorithm, bench, cost_criteria, chararcteristic)
- should be used with mean_values XML only !! --> see GUI for information...
source code
 
__findTopLevelItemName(self, node)
finds the element and returns its tag name
source code
 
__newNode(self, todo, parent) source code
 
__newFromOldNode(node, parent)
builds a new node from the given node including its child nodes and adds it as a child to parent node recurrent function !
source code
 
__getTag(node, parent)
both parameter are node instances of the XML file
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source, mode)
(Constructor)

source code 

__init__

  • parses a XML file given by the path source or creates it
  • mode is the tag name of the top level items
  • root node must be named with mode+"s"
Overrides: object.__init__

nextTopLevelTag(index)

source code 
  • returns a dictionary with: key ... tag name value ... text in XML
  • from the XML entry index Hint: use with countTopLevelItems() to avoid index out of range exception !

writeNewData(dict)

source code 
- writes the data from dict into the XML File
- Attention: XML File must exist and have a root instance. The top level name is set by parsing the XML file --> see __init__
structure of dict:
{

    <key1> : {<key2> : <value2>},
    <key3> : <value3>
}
- results in XML structure:
<root>
    <mode>
        <key1>
            <key2>value2</key2>
        </key1>
    </mode>
</root>

getCharacteristic(data, algorithm, bench, cost_criteria, chararcteristic)

source code 
- should be used with mean_values XML only !! --> see GUI for information
parameter:
- data : string
- algorithm : string
- bench : string
- cost_criteria : list-of-strings
- characteristics : list-of strings
- return:
    dict with structure:
        {
            criteria 1 : { char1 : value , char2 : value},
            criteria 2 : { char1 : value, char2 : value}
        }
    or: {} if not found