-
Notifications
You must be signed in to change notification settings - Fork 77
Closed
Labels
Milestone
Description
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:
- It can override the
elementMapfor 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. - A sub-section of the document may have a different baseUri (e.g.:
xml:baseURI). - 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.