eu.cdevreeze.yaidom

docaware

package docaware

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:

// Note the import of package docaware, and not of its members. That is indeed a best practice!
import eu.cdevreeze.yaidom.docaware

val docawareBookstoreElem = docaware.Elem(bookstoreElem)

val scalaBookAuthors =
  for {
    bookElem <- docawareBookstoreElem \ EName("{http://bookstore/book}Book")
    if (bookElem \@ EName("ISBN")) == Some("978-0981531649")
    authorElem <- bookElem \\ EName("{http://bookstore/author}Author")
  } yield authorElem

The query for Scala book authors would have been exactly the same if normal Elems had been used instead of docaware.Elems (replacing docawareBookstoreElem by bookstoreElem)!

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. docaware
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. final class Document extends DocumentApi[Elem] with Immutable

    Document, containing a "document-aware" document element.

  2. final class Elem extends ScopedElemLike[Elem] with IsNavigable[Elem] with Immutable

    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.

Value Members

  1. object Document

  2. object Elem

Inherited from AnyRef

Inherited from Any

Ungrouped