def parseLiteral(inFileName, silence=False, print_warnings=True): parser = None doc = parsexml_(inFileName, parser) gds_collector = GdsCollector_() rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: rootTag = 'eVSICancelRequest' rootClass = eVSICancelRequest rootObj = rootClass.factory() rootObj.build(rootNode, gds_collector_=gds_collector) # Enable Python to collect the space used by the DOM. if not SaveElementTreeNode: doc = None rootNode = None if not silence: sys.stdout.write('#from evsi_cancel_request import *\n\n') sys.stdout.write('import evsi_cancel_request as model_\n\n') sys.stdout.write('rootObj = model_.rootClass(\n') rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) sys.stdout.write(')\n') if print_warnings and len(gds_collector.get_messages()) > 0: separator = ('-' * 50) + '\n' sys.stderr.write(separator) sys.stderr.write('----- Warnings -- count: {} -----\n'.format( len(gds_collector.get_messages()), )) gds_collector.write_messages(sys.stderr) sys.stderr.write(separator) return rootObj
def parseEtree(inFileName, silence=False, print_warnings=True, mapping=None, nsmap=None): parser = None doc = parsexml_(inFileName, parser) gds_collector = GdsCollector_() rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: rootTag = 'eVSICancelRequest' rootClass = eVSICancelRequest rootObj = rootClass.factory() rootObj.build(rootNode, gds_collector_=gds_collector) # Enable Python to collect the space used by the DOM. if mapping is None: mapping = {} rootElement = rootObj.to_etree( None, name_=rootTag, mapping_=mapping, nsmap_=nsmap) reverse_mapping = rootObj.gds_reverse_node_mapping(mapping) if not SaveElementTreeNode: doc = None rootNode = None if not silence: content = etree_.tostring( rootElement, pretty_print=True, xml_declaration=True, encoding="utf-8") sys.stdout.write(str(content)) sys.stdout.write('\n') if print_warnings and len(gds_collector.get_messages()) > 0: separator = ('-' * 50) + '\n' sys.stderr.write(separator) sys.stderr.write('----- Warnings -- count: {} -----\n'.format( len(gds_collector.get_messages()), )) gds_collector.write_messages(sys.stderr) sys.stderr.write(separator) return rootObj, rootElement, mapping, reverse_mapping
def parseString(inString, silence=False, print_warnings=True): '''Parse a string, create the object tree, and export it. Arguments: - inString -- A string. This XML fragment should not start with an XML declaration containing an encoding. - silence -- A boolean. If False, export the object. Returns -- The root object in the tree. ''' parser = None rootNode= parsexmlstring_(inString, parser) gds_collector = GdsCollector_() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: rootTag = 'eVSICancelRequest' rootClass = eVSICancelRequest rootObj = rootClass.factory() rootObj.build(rootNode, gds_collector_=gds_collector) if not SaveElementTreeNode: rootNode = None if not silence: sys.stdout.write('<?xml version="1.0" ?>\n') rootObj.export( sys.stdout, 0, name_=rootTag, namespacedef_='') if print_warnings and len(gds_collector.get_messages()) > 0: separator = ('-' * 50) + '\n' sys.stderr.write(separator) sys.stderr.write('----- Warnings -- count: {} -----\n'.format( len(gds_collector.get_messages()), )) gds_collector.write_messages(sys.stderr) sys.stderr.write(separator) return rootObj
def parse(inFileName, silence=False, print_warnings=True): global CapturedNsmap_ gds_collector = GdsCollector_() parser = None doc = parsexml_(inFileName, parser) rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: rootTag = 'eVSICancelRequest' rootClass = eVSICancelRequest rootObj = rootClass.factory() rootObj.build(rootNode, gds_collector_=gds_collector) CapturedNsmap_, namespacedefs = get_required_ns_prefix_defs(rootNode) if not SaveElementTreeNode: doc = None rootNode = None if not silence: sys.stdout.write('<?xml version="1.0" ?>\n') rootObj.export( sys.stdout, 0, name_=rootTag, namespacedef_=namespacedefs, pretty_print=True) if print_warnings and len(gds_collector.get_messages()) > 0: separator = ('-' * 50) + '\n' sys.stderr.write(separator) sys.stderr.write('----- Warnings -- count: {} -----\n'.format( len(gds_collector.get_messages()), )) gds_collector.write_messages(sys.stderr) sys.stderr.write(separator) return rootObj