Re: [Generateds-discuss] Namespace Removal in Exported XML
Brought to you by:
dkuhlman
|
From: Dave K. <dku...@da...> - 2021-09-13 19:49:45
|
Jon,
Were you able to resolve your problem.
Here is another idea -- Post-process the exported XML output.
Here is a bit of code (found on the Web) that will strip namespece
definitions and namespace prefixes:
doc = etree.parse("myfile.xml")
root = doc.getroot()
for elem in root.iter():
elem.tag = etree.QName(elem).localname
etree.cleanup_namespaces(root)
with open("mynewfile.xml", 'wb') as outfile:
doc.write(outfile)
I've attached a more complete script that does this.
By the way, opening the output file in binary mode seems weird to
me. Alternatively, you could write to `outfile.buffer` or convert
to string with `etree.tostring(r, encoding='utf-8')`. They all seem
about the same. Take your pick.
Dave
On Thu 09 Sep 2021 01:36:41 PM PDT, Falcon Programmer wrote:
> Hi,
>
> Is it possible to remove the namespace generated when exporting via a
> generateds?
>
> I tried setting the 'namespaceprefix_' on the export, and also tried
> '.set_ns_prefix_' on the object itself and it doesn't seem to have
> made a difference.
>
> I need to do this as I'm submitting an XML that needs to be a specific
> format without the namespace specified.
>
> Thanks,
>
> Jon
>
>
> _______________________________________________
> Generateds-discuss mailing list
> Gen...@li...
> https://lists.sourceforge.net/lists/listinfo/generateds-discuss
--
Dave Kuhlman
http://www.davekuhlman.org
|