Hi all, i've problems converting the given schema. The root element (Resource) does not show up anywhere in the generated code, and thus, parsing only gives my an empty myString element. I used the following command to generate test.py
python generateDS.py -f -a "" \--namespacedef='xmlns:ms="http://www.dfki.de/testschema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.dfki.de/testschema" elementFormDefault="qualified" attributeFormDefault="unqualified"' \
-o test.py \
testschema.xsd
omitting `-a ""' or using `-a "ms:"' also did not help.
Any suggestions?
Thanks in advance,
Bernd Kiefer
--
----------------------------------------------------------------------
Bernd Kiefer DFKI GmbH, Stuhlsatzenhausweg, D-66123 Saarbruecken
[email protected] +49-681/85775-5301 (phone) +49-681/85775-5338 (fax)
----------------------------------------------------------------------
Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
Trippstadter Strasse 122, D-67663 Kaiserslautern, Germany
Geschaeftsfuehrung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vor-
sitzender), Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
testschema.xsd
Description: XML document
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated Wed Nov 9 12:14:08 2011 by generateDS.py version 2.6b.
#
import sys
import getopt
import re as re_
etree_ = None
Verbose_import_ = False
( XMLParser_import_none, XMLParser_import_lxml,
XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
# lxml
from lxml import etree as etree_
XMLParser_import_library = XMLParser_import_lxml
if Verbose_import_:
print("running with lxml.etree")
except ImportError:
try:
# cElementTree from Python 2.5+
import xml.etree.cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# ElementTree from Python 2.5+
import xml.etree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree")
except ImportError:
raise ImportError("Failed to import ElementTree from any known place")
def parsexml_(*args, **kwargs):
if (XMLParser_import_library == XMLParser_import_lxml and
'parser' not in kwargs):
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
kwargs['parser'] = etree_.ETCompatXMLParser()
doc = etree_.parse(*args, **kwargs)
return doc
#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
# in a module named generatedssuper.py.
try:
from generatedssuper import GeneratedsSuper
except ImportError, exp:
class GeneratedsSuper(object):
def gds_format_string(self, input_data, input_name=''):
return input_data
def gds_validate_string(self, input_data, node, input_name=''):
return input_data
def gds_format_integer(self, input_data, input_name=''):
return '%d' % input_data
def gds_validate_integer(self, input_data, node, input_name=''):
return input_data
def gds_format_integer_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_integer_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of integers')
return input_data
def gds_format_float(self, input_data, input_name=''):
return '%f' % input_data
def gds_validate_float(self, input_data, node, input_name=''):
return input_data
def gds_format_float_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_float_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of floats')
return input_data
def gds_format_double(self, input_data, input_name=''):
return '%e' % input_data
def gds_validate_double(self, input_data, node, input_name=''):
return input_data
def gds_format_double_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_double_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of doubles')
return input_data
def gds_format_boolean(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_boolean(self, input_data, node, input_name=''):
return input_data
def gds_format_boolean_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_boolean_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
if value not in ('true', '1', 'false', '0', ):
raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")')
return input_data
def gds_str_lower(self, instring):
return instring.lower()
def get_path_(self, node):
path_list = []
self.get_path_list_(node, path_list)
path_list.reverse()
path = '/'.join(path_list)
return path
Tag_strip_pattern_ = re_.compile(r'\{.*\}')
def get_path_list_(self, node, path_list):
if node is None:
return
tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
if tag:
path_list.append(tag)
self.get_path_list_(node.getparent(), path_list)
def get_class_obj_(self, node, default_class=None):
class_obj1 = default_class
if 'xsi' in node.nsmap:
classname = node.get('{%s}type' % node.nsmap['xsi'])
if classname is not None:
names = classname.split(':')
if len(names) == 2:
classname = names[1]
class_obj2 = globals().get(classname)
if class_obj2 is not None:
class_obj1 = class_obj2
return class_obj1
#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#
## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
## banner = 'Dropping into IPython',
## exit_msg = 'Leaving Interpreter, back to program.')
# Then use the following line where and when you want to drop into the
# IPython shell:
# ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
#
# Globals
#
ExternalEncoding = 'ascii'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')
#
# Support/utility functions.
#
def showIndent(outfile, level):
for idx in range(level):
outfile.write(' ')
def quote_xml(inStr):
if not inStr:
return ''
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
return s1
def quote_attrib(inStr):
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
if '"' in s1:
if "'" in s1:
s1 = '"%s"' % s1.replace('"', """)
else:
s1 = "'%s'" % s1
else:
s1 = '"%s"' % s1
return s1
def quote_python(inStr):
s1 = inStr
if s1.find("'") == -1:
if s1.find('\n') == -1:
return "'%s'" % s1
else:
return "'''%s'''" % s1
else:
if s1.find('"') != -1:
s1 = s1.replace('"', '\\"')
if s1.find('\n') == -1:
return '"%s"' % s1
else:
return '"""%s"""' % s1
def get_all_text_(node):
if node.text is not None:
text = node.text
else:
text = ''
for child in node:
if child.tail is not None:
text += child.tail
return text
def find_attr_value_(attr_name, node):
attrs = node.attrib
attr_parts = attr_name.split(':')
value = None
if len(attr_parts) == 1:
value = attrs.get(attr_name)
elif len(attr_parts) == 2:
prefix, name = attr_parts
namespace = node.nsmap.get(prefix)
if namespace is not None:
value = attrs.get('{%s}%s' % (namespace, name, ))
return value
class GDSParseError(Exception):
pass
def raise_parse_error(node, msg):
if XMLParser_import_library == XMLParser_import_lxml:
msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, )
else:
msg = '%s (element %s)' % (msg, node.tag, )
raise GDSParseError(msg)
class MixedContainer:
# Constants for category:
CategoryNone = 0
CategoryText = 1
CategorySimple = 2
CategoryComplex = 3
# Constants for content_type:
TypeNone = 0
TypeText = 1
TypeString = 2
TypeInteger = 3
TypeFloat = 4
TypeDecimal = 5
TypeDouble = 6
TypeBoolean = 7
def __init__(self, category, content_type, name, value):
self.category = category
self.content_type = content_type
self.name = name
self.value = value
def getCategory(self):
return self.category
def getContenttype(self, content_type):
return self.content_type
def getValue(self):
return self.value
def getName(self):
return self.name
def export(self, outfile, level, name, namespace):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
outfile.write(self.value)
elif self.category == MixedContainer.CategorySimple:
self.exportSimple(outfile, level, name)
else: # category == MixedContainer.CategoryComplex
self.value.export(outfile, level, namespace,name)
def exportSimple(self, outfile, level, name):
if self.content_type == MixedContainer.TypeString:
outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeInteger or \
self.content_type == MixedContainer.TypeBoolean:
outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeFloat or \
self.content_type == MixedContainer.TypeDecimal:
outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeDouble:
outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))
def exportLiteral(self, outfile, level, name):
if self.category == MixedContainer.CategoryText:
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
(self.category, self.content_type, self.name, self.value))
elif self.category == MixedContainer.CategorySimple:
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \
(self.category, self.content_type, self.name, self.value))
else: # category == MixedContainer.CategoryComplex
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \
(self.category, self.content_type, self.name,))
self.value.exportLiteral(outfile, level + 1)
showIndent(outfile, level)
outfile.write(')\n')
class MemberSpec_(object):
def __init__(self, name='', data_type='', container=0):
self.name = name
self.data_type = data_type
self.container = container
def set_name(self, name): self.name = name
def get_name(self): return self.name
def set_data_type(self, data_type): self.data_type = data_type
def get_data_type_chain(self): return self.data_type
def get_data_type(self):
if isinstance(self.data_type, list):
if len(self.data_type) > 0:
return self.data_type[-1]
else:
return 'xs:string'
else:
return self.data_type
def set_container(self, container): self.container = container
def get_container(self): return self.container
def _cast(typ, value):
if typ is None or value is None:
return value
return typ(value)
#
# Data representation classes.
#
class myString(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, lang=None, valueOf_=None):
self.lang = _cast(None, lang)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if myString.subclass:
return myString.subclass(*args_, **kwargs_)
else:
return myString(*args_, **kwargs_)
factory = staticmethod(factory)
def get_lang(self): return self.lang
def set_lang(self, lang): self.lang = lang
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def export(self, outfile, level, namespace_='ms:', name_='myString', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = []
self.exportAttributes(outfile, level, already_processed, namespace_, name_='myString')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_)
outfile.write('</%s%s>\n' % (namespace_, name_))
else:
outfile.write('/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='ms:', name_='myString'):
if self.lang is not None and 'lang' not in already_processed:
already_processed.append('lang')
outfile.write(' lang=%s' % (self.gds_format_string(quote_attrib(self.lang).encode(ExternalEncoding), input_name='lang'), ))
def exportChildren(self, outfile, level, namespace_='ms:', name_='myString', fromsubclass_=False):
pass
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='myString'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.lang is not None and 'lang' not in already_processed:
already_processed.append('lang')
showIndent(outfile, level)
outfile.write('lang = "%s",\n' % (self.lang,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
self.buildAttributes(node, node.attrib, [])
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('lang', node)
if value is not None and 'lang' not in already_processed:
already_processed.append('lang')
self.lang = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class myString
class PersonInfoType(GeneratedsSuper):
"""PersonType"""
subclass = None
superclass = None
def __init__(self, surname=None, givenName=None):
self.surname = surname
self.givenName = givenName
def factory(*args_, **kwargs_):
if PersonInfoType.subclass:
return PersonInfoType.subclass(*args_, **kwargs_)
else:
return PersonInfoType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_surname(self): return self.surname
def set_surname(self, surname): self.surname = surname
def get_givenName(self): return self.givenName
def set_givenName(self, givenName): self.givenName = givenName
def export(self, outfile, level, namespace_='ms:', name_='PersonInfoType', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = []
self.exportAttributes(outfile, level, already_processed, namespace_, name_='PersonInfoType')
if self.hasContent_():
outfile.write('>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write('</%s%s>\n' % (namespace_, name_))
else:
outfile.write('/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='ms:', name_='PersonInfoType'):
pass
def exportChildren(self, outfile, level, namespace_='ms:', name_='PersonInfoType', fromsubclass_=False):
if self.surname:
self.surname.export(outfile, level, namespace_, name_='surname')
if self.givenName:
self.givenName.export(outfile, level, namespace_, name_='givenName')
def hasContent_(self):
if (
self.surname is not None or
self.givenName is not None
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='PersonInfoType'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.surname is not None:
showIndent(outfile, level)
outfile.write('surname=model_.myString(\n')
self.surname.exportLiteral(outfile, level, name_='surname')
showIndent(outfile, level)
outfile.write('),\n')
if self.givenName is not None:
showIndent(outfile, level)
outfile.write('givenName=model_.myString(\n')
self.givenName.exportLiteral(outfile, level, name_='givenName')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'surname':
obj_ = myString.factory()
obj_.build(child_)
self.set_surname(obj_)
elif nodeName_ == 'givenName':
obj_ = myString.factory()
obj_.build(child_)
self.set_givenName(obj_)
# end class PersonInfoType
class IdentificationInfoType(GeneratedsSuper):
"""Identification Component"""
subclass = None
superclass = None
def __init__(self, resourceName=None, resourceShortName=None):
self.resourceName = resourceName
self.resourceShortName = resourceShortName
def factory(*args_, **kwargs_):
if IdentificationInfoType.subclass:
return IdentificationInfoType.subclass(*args_, **kwargs_)
else:
return IdentificationInfoType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_resourceName(self): return self.resourceName
def set_resourceName(self, resourceName): self.resourceName = resourceName
def get_resourceShortName(self): return self.resourceShortName
def set_resourceShortName(self, resourceShortName): self.resourceShortName = resourceShortName
def export(self, outfile, level, namespace_='ms:', name_='IdentificationInfoType', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = []
self.exportAttributes(outfile, level, already_processed, namespace_, name_='IdentificationInfoType')
if self.hasContent_():
outfile.write('>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write('</%s%s>\n' % (namespace_, name_))
else:
outfile.write('/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='ms:', name_='IdentificationInfoType'):
pass
def exportChildren(self, outfile, level, namespace_='ms:', name_='IdentificationInfoType', fromsubclass_=False):
if self.resourceName:
self.resourceName.export(outfile, level, namespace_, name_='resourceName', )
if self.resourceShortName:
self.resourceShortName.export(outfile, level, namespace_, name_='resourceShortName')
def hasContent_(self):
if (
self.resourceName is not None or
self.resourceShortName is not None
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='IdentificationInfoType'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.resourceName is not None:
showIndent(outfile, level)
outfile.write('resourceName=model_.myString(\n')
self.resourceName.exportLiteral(outfile, level, name_='resourceName')
showIndent(outfile, level)
outfile.write('),\n')
if self.resourceShortName is not None:
showIndent(outfile, level)
outfile.write('resourceShortName=model_.myString(\n')
self.resourceShortName.exportLiteral(outfile, level, name_='resourceShortName')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'resourceName':
obj_ = myString.factory()
obj_.build(child_)
self.set_resourceName(obj_)
elif nodeName_ == 'resourceShortName':
obj_ = myString.factory()
obj_.build(child_)
self.set_resourceShortName(obj_)
# end class IdentificationInfoType
class ResourceType(GeneratedsSuper):
"""core element"""
subclass = None
superclass = None
def __init__(self, IdentificationInfo=None, PersonInfo=None):
self.IdentificationInfo = IdentificationInfo
if PersonInfo is None:
self.PersonInfo = []
else:
self.PersonInfo = PersonInfo
def factory(*args_, **kwargs_):
if ResourceType.subclass:
return ResourceType.subclass(*args_, **kwargs_)
else:
return ResourceType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_IdentificationInfo(self): return self.IdentificationInfo
def set_IdentificationInfo(self, IdentificationInfo): self.IdentificationInfo = IdentificationInfo
def get_PersonInfo(self): return self.PersonInfo
def set_PersonInfo(self, PersonInfo): self.PersonInfo = PersonInfo
def add_PersonInfo(self, value): self.PersonInfo.append(value)
def insert_PersonInfo(self, index, value): self.PersonInfo[index] = value
def export(self, outfile, level, namespace_='ms:', name_='ResourceType', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = []
self.exportAttributes(outfile, level, already_processed, namespace_, name_='ResourceType')
if self.hasContent_():
outfile.write('>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write('</%s%s>\n' % (namespace_, name_))
else:
outfile.write('/>\n')
def exportAttributes(self, outfile, level, already_processed, namespace_='ms:', name_='ResourceType'):
pass
def exportChildren(self, outfile, level, namespace_='ms:', name_='ResourceType', fromsubclass_=False):
if self.IdentificationInfo:
self.IdentificationInfo.export(outfile, level, namespace_, name_='IdentificationInfo', )
for PersonInfo_ in self.PersonInfo:
PersonInfo_.export(outfile, level, namespace_, name_='PersonInfo')
def hasContent_(self):
if (
self.IdentificationInfo is not None or
self.PersonInfo
):
return True
else:
return False
def exportLiteral(self, outfile, level, name_='ResourceType'):
level += 1
self.exportLiteralAttributes(outfile, level, [], name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.IdentificationInfo is not None:
showIndent(outfile, level)
outfile.write('IdentificationInfo=model_.IdentificationInfo(\n')
self.IdentificationInfo.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('PersonInfo=[\n')
level += 1
for PersonInfo_ in self.PersonInfo:
showIndent(outfile, level)
outfile.write('model_.PersonInfo(\n')
PersonInfo_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
self.buildAttributes(node, node.attrib, [])
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'IdentificationInfo':
obj_ = IdentificationInfoType.factory()
obj_.build(child_)
self.set_IdentificationInfo(obj_)
elif nodeName_ == 'PersonInfo':
obj_ = PersonInfoType.factory()
obj_.build(child_)
self.PersonInfo.append(obj_)
# end class ResourceType
USAGE_TEXT = """
Usage: python <Parser>.py [ -s ] <in_xml_file>
"""
def usage():
print USAGE_TEXT
sys.exit(1)
def get_root_tag(node):
tag = Tag_pattern_.match(node.tag).groups()[-1]
rootClass = globals().get(tag)
return tag, rootClass
def parse(inFileName):
doc = parsexml_(inFileName)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'myString'
rootClass = myString
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(sys.stdout, 0, name_=rootTag,
namespacedef_='xmlns:ms="http://www.dfki.de/testschema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.dfki.de/testschema" elementFormDefault="qualified" attributeFormDefault="unqualified"')
return rootObj
def parseString(inString):
from StringIO import StringIO
doc = parsexml_(StringIO(inString))
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'myString'
rootClass = myString
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(sys.stdout, 0, name_="myString",
namespacedef_='xmlns:ms="http://www.dfki.de/testschema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.dfki.de/testschema" elementFormDefault="qualified" attributeFormDefault="unqualified"')
return rootObj
def parseLiteral(inFileName):
doc = parsexml_(inFileName)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'myString'
rootClass = myString
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('#from test import *\n\n')
sys.stdout.write('import test as model_\n\n')
sys.stdout.write('rootObj = model_.rootTag(\n')
rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
sys.stdout.write(')\n')
return rootObj
def main():
args = sys.argv[1:]
if len(args) == 1:
parse(args[0])
else:
usage()
if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()
__all__ = [
"IdentificationInfoType",
"PersonInfoType",
"ResourceType",
"myString"
]
<?xml version="1.0" encoding="UTF-8"?> <Resource xsi:schemaLocation="http://www.dfki.de/testschema testschema.xsd" xmlns="http://www.dfki.de/testschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <IdentificationInfo> <resourceName>myResource</resourceName> </IdentificationInfo> <PersonInfo> <surname>Heinz</surname> </PersonInfo> <PersonInfo> <surname>John</surname><givenName>Doe</givenName> </PersonInfo> </Resource>
------------------------------------------------------------------------------ RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________ generateds-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/generateds-users
