93 lines
1.4 KiB
Python
93 lines
1.4 KiB
Python
#! /usr/bin/python
|
|
|
|
# To change this template, choose Tools | Templates
|
|
# and open the template in the editor.
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Jan 4, 2010 3:27:05 PM$"
|
|
|
|
|
|
import xml.dom.minidom as xml
|
|
from bt.file import *
|
|
|
|
global document
|
|
document = None
|
|
|
|
|
|
def new():
|
|
global document
|
|
document = xml.Document()
|
|
|
|
|
|
def element(name):
|
|
global document
|
|
return document.createElement(name)
|
|
|
|
|
|
def text(name):
|
|
global document
|
|
return document.createTextNode(name)
|
|
|
|
|
|
def append(child,root=None):
|
|
if root==None:
|
|
global document
|
|
document.appendChild(child)
|
|
return
|
|
root.appendChild(child)
|
|
|
|
|
|
def child(root=None):
|
|
if root==None:
|
|
global document
|
|
if document == None:
|
|
return
|
|
return document.firstChild
|
|
return root.firstChild
|
|
|
|
|
|
def children(root=None):
|
|
if root == None:
|
|
global document
|
|
if document == None:
|
|
return []
|
|
return document.childNodes
|
|
return root.childNodes
|
|
|
|
|
|
def write(path):
|
|
global document
|
|
out = fopen(path,'w')
|
|
out.write(document.toprettyxml(indent=" "))
|
|
out.close()
|
|
|
|
|
|
def load(path):
|
|
global document
|
|
fin = fopen(path)
|
|
if fin == None:
|
|
return
|
|
document = xml.parse(fin)
|
|
|
|
|
|
def isElm(node):
|
|
return node.nodeType == 1
|
|
|
|
|
|
def isText(node):
|
|
return node.nodeType == 3
|
|
|
|
|
|
def name(node):
|
|
return node.nodeName
|
|
|
|
|
|
def value(node):
|
|
val = node.nodeValue.strip()
|
|
if val == "False":
|
|
return False
|
|
elif val == "True":
|
|
return True
|
|
elif val.isdigit() == True:
|
|
return int(val)
|
|
return val |