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

make xml reader and writer extensible #38

Closed
tomjnixon opened this issue Aug 25, 2021 · 0 comments
Closed

make xml reader and writer extensible #38

tomjnixon opened this issue Aug 25, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@tomjnixon
Copy link
Member

tomjnixon commented Aug 25, 2021

Use cases:

  • read or write metadata from a newer ADM standard, or during development of new standards
  • read or write custom metadata that extends existing ADM structures e.g. custom parameters
  • read or write custom metadata that lives in AXML but outside of existing structures, e.g. tool version information

Implementation ideas:

  1. extend all ADM elements with xml attributes, and use it to (optionally) store a reference to the corresponding XML elements when parsing or generating XML
    • when reading, this can be used to extract extra data from the xml
    • when writing, extra data can be injected into the XML before it's string-ified
    • bad: feels like writing an ADM document shouldn't modify it
    • bad: slightly increases storage even when not used
  2. allow customisation of the XML to python class mapping
    • need to be able to tell parser "when dealing with element X, use this parser and this class"
    • need to be able to tell generator "when dealing with this class, use this un-parser"
    • bad: exposes innards of XML parser to users
    • bad: quite complex to do, especially for block formats. XML parser is already complex enough
  3. when parsing or generating XML, produce a mapping from ADM objects to XML elements
    • question: how to store this mapping?
      • {id(adm_element): xml_element}
      • {id(adm_element): (adm_element, xml_element)}
      • {IDCompare(adm_element): xml_element} where IDCompare is a class that makes an object hashable and comparable by identity
      • some hack to make WeakKeyDictionary work with non-hashable types. It's not clear if weak references are really needed
    • could pass a list into the parser / generator to say which types we want to store
    • could be combined with 2, allowing the user to specify their own sub-classes, but keep parsing / generation external. It should be possible to re-use the parsing infrastructure externally, but this still allows the internal structure to be modified.

After writing this I think 3 is the way to go.

@tomjnixon tomjnixon added the enhancement New feature or request label Aug 25, 2021
tomjnixon added a commit that referenced this issue Jun 30, 2023
now, the building of ElementParser structures is mostly contained in the
MainElementHandler class; things like different versions can be
supported through different instances of this, and the behaviour for
individual elements can be overridden by sub-classing this and passing
instances to the parsing/formatting functions

closes #38

this is option 2, which wasn't the plan, but that didn't consider
needing different behaviours for different versions
tomjnixon added a commit that referenced this issue Oct 3, 2023
now, the building of ElementParser structures is mostly contained in the
MainElementHandler class; things like different versions can be
supported through different instances of this, and the behaviour for
individual elements can be overridden by sub-classing this and passing
instances to the parsing/formatting functions

closes #38

this is option 2, which wasn't the plan, but that didn't consider
needing different behaviours for different versions
tomjnixon added a commit that referenced this issue Nov 7, 2023
now, the building of ElementParser structures is mostly contained in the
MainElementHandler class; things like different versions can be
supported through different instances of this, and the behaviour for
individual elements can be overridden by sub-classing this and passing
instances to the parsing/formatting functions

closes #38

this is option 2, which wasn't the plan, but that didn't consider
needing different behaviours for different versions
tomjnixon added a commit that referenced this issue Nov 7, 2023
now, the building of ElementParser structures is mostly contained in the
MainElementHandler class; things like different versions can be
supported through different instances of this, and the behaviour for
individual elements can be overridden by sub-classing this and passing
instances to the parsing/formatting functions

closes #38

this is option 2, which wasn't the plan, but that didn't consider
needing different behaviours for different versions
tomjnixon added a commit that referenced this issue Nov 16, 2023
now, the building of ElementParser structures is mostly contained in the
MainElementHandler class; things like different versions can be
supported through different instances of this, and the behaviour for
individual elements can be overridden by sub-classing this and passing
instances to the parsing/formatting functions

closes #38

this is option 2, which wasn't the plan, but that didn't consider
needing different behaviours for different versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant