Skip to content

Pushing and popping contexts #16

@evert

Description

@evert

It would be nice if we can allow an Element in a document to start a new 'context' during reading or writing. This has the following advantages:

  1. It can override the elementMap for specific parts of a document. In a lot of (arguably badly designed) xml documents, the meaning of an element may vary depending on which element it's in.
  2. A sub-section of the document may have a different baseUri (e.g.: xml:baseURI).
  3. A sub-section of a document may want to use a different set of xml namespace prefixes. The current writer is restricted to writing all common namespace prefixes at the root of the document.

So it would be awesome if an Element can push a new context. After the 'inner' part of the element has been either serialized or deserialized, the context can be popped again, which will make the reader or writer go back to the previous state.

Example:

function deserializeXml(Reader $reader) {

    $reader->pushContext();
    $reader->elementMap['{DAV:}prop'] = 'SomeClass';
    $result = new self(
       $reader->parseInnerTree()
    );
    $reader->popContext();
    return $result

}

The last example is a deserialize function that tells the reader to use a different reader class for {DAV:}prop elements that are nested within. After reading all inner elements (with parseInnerTree()), the old state is restored.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions