Re: [Generateds-discuss] How to create/ generate new xml from generated API
Brought to you by:
dkuhlman
From: Dewitte, D. W (US) <dan...@ba...> - 2022-06-01 17:14:22
|
Here are the actual files this time :) Daniel DeWitte T: +1-603-885-2602 M: +1-603-759-4476 E: dan...@ba...<mailto:dan...@ba...> From: Dewitte, Daniel W (US) Sent: Wednesday, June 1, 2022 1:06 PM To: 'Gen...@li...' <Gen...@li...> Subject: How to create/ generate new xml from generated API Hi Dave, This is one of the better tools that I have found and I think the only one that can work the way I need it too, I just need some help with getting to the finish line. My goal is generate a new .xml using a known schema .xsd with Python as the base language (required). I have 13 different reports that all have a different format that are generated on a constant basis that I need to import into a known .xsd format for upload to a database. I believe I either want to use the build methods, or the "one-per" options, but I can't get either of them to work. I asked about the build method problem on stackover flow here: Stackoverflow - Creating a new XML from an XSD using GenerateDS and Python<https://stackoverflow.com/questions/72397436/creating-a-new-xml-from-an-xsd-using-generateds-and-python> But I am not sure that the build method is what I want to use. When I try the "one-per" I get the following errors: Command line method, I believe this error is due to that the .xsd is in a UTF-8 encoding. How do I get this to work with UTF-8 encoding? >(base) H:\Python Training\GenerateDS_Docs>python generateds.py --one-file-per-xsd --output-directory="OnePer" --module-suffix="One" TestResults.xsd >Traceback (most recent call last): > File "H:\Python Training\GenerateDS_Docs\generateds.py", line 9906, in <module> main() > File "H:\Python Training\GenerateDS_Docs\generateds.py", line 9872, in main parseAndGenerate( > File "H:\Python Training\GenerateDS_Docs\generateds.py", line 9318, in parseAndGenerate parser.parse(rootFile) > File "C:\EngTools\Anaconda3\lib\xml\sax\expatreader.py", line 111, in parse xmlreader.IncrementalParser.parse(self, source) > File "C:\EngTools\Anaconda3\lib\xml\sax\xmlreader.py", line 123, in parse buffer = file.read(self._bufsize) > File "C:\EngTools\Anaconda3\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 4013: character maps to <undefined> Approach 2 - Extraction and Generation Utilities: > (base) h:\Python Training\GenerateDS_Docs\utils>python collect_schema_locations.py --force --verbose TestResults.xsd testJson.txt > Traceback (most recent call last): > File "h:\Python Training\GenerateDS_Docs\utils\collect_schema_locations.py", line 157, in <module> main() > File "h:\Python Training\GenerateDS_Docs\utils\collect_schema_locations.py", line 148, in main extract_and_generate(infile, outfile, extract_locations_fn, options) > File "h:\Python Training\GenerateDS_Docs\utils\collect_schema_locations.py", line 86, in extract_and_generate locations = extract_locations(infile, options) > File "h:\Python Training\GenerateDS_Docs\utils\collect_schema_locations.py", line 50, in extract_locations elements = root.xpath('xs:import', namespaces=root.nsmap) > File "src/lxml/etree.pyx", line 1579, in lxml.etree._Element.xpath > File "src/lxml/xpath.pxi", line 259, in lxml.etree.XPathElementEvaluator.__init__ > File "src/lxml/xpath.pxi", line 131, in lxml.etree._XPathEvaluatorBase.__init__ > File "src/lxml/xpath.pxi", line 55, in lxml.etree._XPathContext.__init__ > File "src/lxml/extensions.pxi", line 81, in lxml.etree._BaseContext.__init__ > TypeError: empty namespace prefix is not supported in XPath Attached are the .xsd that I am using. TestResults.xsd references Common.xsd. Any help on getting started with my overall goal will be much appreciated. I am looking to create a new XML from a known .xsd and add in the elements and child elements and attributes as needed. Thank you for the help, Daniel DeWitte |