AcademySoftwareFoundation/MaterialX

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

kwokcb opened this issue · 2 comments

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).