Open henrihi opened 1 month ago
Hi there! Indeed, this is currently kind of fixed. It happens because the root rag is chosen by https://github.com/khaeru/sdmx/blob/e88f8d33cedccb003194666564494640e6fa95d4/sdmx/writer/xml.py#L124-L131 and https://github.com/khaeru/sdmx/blob/e88f8d33cedccb003194666564494640e6fa95d4/sdmx/format/xml/common.py#L74-L79
The latter gives defaults used for both SDMX-ML 2.1 and 3.0.0. I guess it should only be the default for SDMX-ML 3.0.0 (where it is the only option given by the standard), and for SDMX-ML 2.1 the code could instead peek ahead and choose <mes:GenericData>
if the contained data sets are not structure-specific.
The underlying package lxml writes out all of the XML namespace (xmlns:
) attributes that appear on the root tag or any of its children. The set of namespaces and prefixes is determined further up in the same file:
https://github.com/khaeru/sdmx/blob/e88f8d33cedccb003194666564494640e6fa95d4/sdmx/writer/xml.py#L22
So this could also be adapted to (a) differ for SDMX-ML 2.1 and 3.0 and (b) only include …/{meta}data/structurespecific
or …/{meta}data/generic
, as appropriate.
A PR would be welcome. As a workaround you could use lxml directly to manipulate the returned XML or file.
Hi,
I am trying to create an SDMX-ML (.xml) file with
<mes:GenericData>
as the root of the .xml file. However thesdmx.to_xml()
function seem to produce an .xml file with<mes:StructureSpecificData>
as the root regardless:Here is my code:
Is there any way to produce a .xml file with
<mes:GenericData>
as the root using thesdmx.to_xml()
function? Also, is it possible to change the root attributes? I would also like to remove thexmlns:data="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific"
attribute.