46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from .LibraryParser import LibraryParser
|
|
|
|
from xml.dom import minidom, Node
|
|
from xml.dom.minidom import Entity
|
|
|
|
class XMLLibraryParser(LibraryParser):
|
|
|
|
def load_instance(self, xmlnode):
|
|
print("instance : [" + xmlnode.getAttribute("id") + "]")
|
|
|
|
def load_library(self, xmlnode):
|
|
"""
|
|
Loads a library from the specified XML node.
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
if xmlnode.tagName != "library":
|
|
return
|
|
|
|
id = xmlnode.getAttribute("id")
|
|
for child in xmlnode.childNodes:
|
|
if child.tagName == "instances":
|
|
for child2 in child.childNodes:
|
|
self.load_library_instance_from_xml(child)
|
|
|
|
|
|
def load_file(self, filename):
|
|
print("loading xml from " + filename + "... ")
|
|
|
|
dom = minidom.getDOMImplementation()
|
|
dt = dom.createDocumentType("mocha", "-//MBS//DTD Mocha 1.0 Dev//EN", "https://doctype.schemas.alcetech.net/Mocha/1.0/mocha-1.0.dtd")
|
|
dt.entities.setNamedItem(Entity("IDC_ReturnInstanceSetMethodBinding", "{AADC20F9-7559-429B-AEF0-97E059295C76}", None, None))
|
|
|
|
dom = minidom.parse(filename)
|
|
if (dom.documentElement.tagName != "mocha"):
|
|
print(filename + ": top-level tag is not 'mocha'")
|
|
return
|
|
|
|
for child in dom.documentElement.childNodes:
|
|
if child.nodeType == Node.ELEMENT_NODE:
|
|
if child.tagName == "libraries":
|
|
for child2 in child.childNodes:
|
|
self.load_library(child)
|
|
|
|
print ("\n") |