Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow StructureSpecific in XML writer #65

Closed
brockfanning opened this issue Mar 4, 2021 · 3 comments · Fixed by #67
Closed

Allow StructureSpecific in XML writer #65

brockfanning opened this issue Mar 4, 2021 · 3 comments · Fixed by #67
Labels
enh Enhancements & new features

Comments

@brockfanning
Copy link

If I'm understanding the DataMessage section in the XML writer code it will always produce "Generic" output. Would it be possible to allow "StructureSpecific" as an alternative?

If so, and you can summarize what needs to happen, I would be happy to submit a pull request. I tried locally just by changing "Generic" to "StructureSpecific" in the line linked above, but that does not alter the inner structure. For example, the output still has "SeriesKey" elements, which to my knowledge is not in StructureSpecific.

@khaeru khaeru added the enh Enhancements & new features label Mar 4, 2021
@khaeru
Copy link
Owner

khaeru commented Mar 4, 2021

Certainly possible and a desirable enhancement, but non-trivial.

The summary: the "inner structure" is generated by the rest of the code in the function you linked to. Every call to writer.recurse() within that function results in a call to a different method in the same file. For instance:

sdmx/sdmx/writer/xml.py

Lines 130 to 131 in 3e4cbc1

# Add data
elem.append(writer.recurse(ds))

In this case, ds is an instance of model.DataSet. So the writer finds another method that accepts this type of object:

sdmx/sdmx/writer/xml.py

Lines 541 to 542 in 3e4cbc1

@writer
def _ds(obj: model.DataSet):

…and calls that, which in turn recurses for the constituent classes like SeriesKey, Observation, etc. Each method returns lxml Element objects, that are assembled (e.g. elem.append()) into the complete XML document.

In order to output structure-specific SDMX-ML, every such method would need to be extended to (a) check whether generic or structure-specific output is to be produced and (b) if the latter, generate the XML elements and attributes that the standard requires for structure-specific data.

(The experiment you mention only changed the name of one particular generated XML element—because it did not alter any of the other code that generates the elements and attributes, the output does not change.)

A PR for this would also need appropriate extensions to the test suite.

@brockfanning
Copy link
Author

@khaeru Thanks, the makes sense. Do you think the Generic and StructureSpecific are pretty much the entirety of the possible formats? Or should this be done in a way that allows for other formats in the future?

@khaeru
Copy link
Owner

khaeru commented Mar 5, 2021

Coding a standards-compliant implementation will require careful attention to the actual standards documents, which will answer that and other questions 🙂 The SDMX website seems to be down at this moment (?!), but here's an archived version: https://web.archive.org/web/20200912164322/https://sdmx.org/?page_id=5008 —§3A is the one you want to consult.

For the moment, if each of the affected functions in sdmx.writer.xml contains an if/else block with just 2 clauses, that's fine from my point of view. If it became a performance concern (cf. #49) or the code ends up being too complex, then we could try a pattern of using one set of functions for generic data but a distinct set of functions for structure-specific data. Let's cross that bridge if we come to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh Enhancements & new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants