Document
, containing a "document-aware" document element.
An element just like indexed.Elem
, but storing the containing document URI (and base URI) as well.
An element just like indexed.Elem
, but storing the containing document URI (and base URI) as well. See eu.cdevreeze.yaidom.indexed.Elem
for more details. These details apply to eu.cdevreeze.yaidom.docaware.Elem too, except that additionally the document and base URIs
are stored.
If XML Base support is important, but the documents may have no document URI, still consider using docaware
elements,
using the empty URI as document URI. Note that the empty URI is a relative URI, containing only an empty path, and
that resolving URIs against the empty URI leaves those URIs the same. XML Base processing is still possible if
the document URI is empty and the XML Base attributes also contain only relative URIs, as long as one is aware of it.
Of course, the user of the API is free to reject those relative base URIs.
With respect to empty (string) emptyUri
, the following holds:
emptyUri.resolve(uri) == uri
// If uri ends in a slash, so its path ends in a slash (and there is no query string and fragment):
uri.resolve(emptyUri) == uri
The base URI of an element elem
can be defined as follows:
val ancestorsOrSelf = elem.path.ancestorOrSelfPaths.reverse.map(p => elem.rootElem.getElemOrSelfByPath(p)) val baseUri = ancestorsOrSelf.foldLeft(elem.docUri) { case (currBaseUri, e) => e.attributeOption(XmlBaseEName).map(s => currBaseUri.resolve(new URI(s))).getOrElse(currBaseUri) }
although the implementation is not this inefficient.
Hence, the base URI of element elem
is:
elem.attributeOption(XmlBaseEName).map(s => elem.parentBaseUri.resolve(new URI(s))).getOrElse(elem.parentBaseUri)
Note the analogy with Scope resolution, where base URIs and parent base URIs map to scopes and parent scopes, and where XML Base attributes map to namespace declarations.
This package contains element representations that contain the "context" of the element, including the URI of the containing document. In other words, this package contains element representations like
indexed.Elem
, except that the document URI is stored as well in each element.Below follows a simple example query, using the uniform query API:
The query for Scala book authors would have been exactly the same if normal
Elem
s had been used instead ofdocaware.Elem
s (replacingdocawareBookstoreElem
bybookstoreElem
)!