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

Proposal: Add a simple way to strip out library content on XML write #1991

Open
kwokcb opened this issue Aug 27, 2024 · 0 comments
Open

Proposal: Add a simple way to strip out library content on XML write #1991

kwokcb opened this issue Aug 27, 2024 · 0 comments

Comments

@kwokcb
Copy link
Contributor

kwokcb commented Aug 27, 2024

Issue

Currently a document needs to import the standard libraries to use any of the node definitions available.
This get's embedded inside the working document. When writing to XML, this content get's embedded inside the
document which can often be undesirable.

You thus need to either create a write predicate function and pass this over to XmlWriteOptions or
traverse and prune yourself. This is highly dependent on knowing to look for items with source URIs.

Proposal 1

Add a new convenience option on XmlWriteOptions to automatically strip out these libraries using a built in / predefined predicate.
Perhaps something as simple as a writeLibraries boolean. If this was done by default then the user would only provide the options to disable -- but this breaks current behaviour so is probably undesirable.

Proposal 2

Add a convenient function to strip out library content (referenced content). Something like this:

def removeReferencedElements(doc):
    """
    Remove any elements which are referenced in. That is has a source URI.
    """
    for elem in doc.getChildren():
        if elem.hasSourceUri():
            doc.removeChild(elem.getName())

(The alternative of keeping reference documents for standard libraries -- which would mean there is nothing to prune
has already been proposed but no design has been finalized currently).

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

No branches or pull requests

1 participant