November 28, 2014
Hot Topics:

Understanding the XPath Data Model

  • May 14, 2004
  • By Steven Holzner
  • Send Email »
  • More Articles »

Element Nodes

Element nodes encapsulate XML elements. In the XPath 2.0 data model, elements have these properties:

In addition, element nodes must have a type annotation, which indicates what type of element they are. (As mentioned earlier, exactly how the type annotation works is implementation-specific at this point, and is not defined by XPath 2.0.) Element nodes must also have a unique identity, distinct from all other nodes. If there are children, the children of an element must be only element, processing instruction, comment, and text nodes. Attribute, namespace, and document nodes cannot be element node children.

Also, the children property may not contain two consecutive text nodes, and the sequence of nodes in the children property is ordered (in document order). The attributes of elements must have distinct names, as well as the namespace modes of an element, if there are any. And no namespace node may have the name "xmlns".


Element and Attribute Nodes That Do Not Have Parents - The XPath 2.0 data model supports element and attribute nodes that do not have parents. It does this to let you work with partial results during expression processing. However, as you'd expect, these elements or attributes may not be children of any other node.


Included in the PSVI for element nodes is this kind of information:

  • The element's base URI

  • The node kind (which returns "element" here)

  • The node name (which is the qualified name of the element)

  • The parent of the element

  • Its string value

  • Its typed value

  • The children of the element if there are any

  • Its attributes

  • Its namespaces, if there are any

Attribute Nodes

In the XPath 2.0 data model, attribute nodes encapsulate XML attributes. Attributes have these properties:

  • node-name

  • string-value

  • parent

  • type

In XPath 2.0, attribute nodes must have a type annotation, which indicates what type of element they are. Attribute nodes must also have a unique identity, distinct from all other nodes. Note that in XPath 2.0, the element node that owns an attribute is often called its parent. However, an attribute node is not considered a child of its parent element.

Included in the information about an attribute in the PSVI are its base URI, node kind (which is "attribute" here), its node name (which is the qualified name of the attribute), its parent element, its string value, its typed value, and its type.

Namespace Nodes

In XPath 2.0, namespace nodes encapsulate XML namespaces. Namespaces have these properties in the XPath 2.0 data model:

  • prefix

  • uri

  • parent

Namespace nodes must have a unique identity, distinct from all other nodes. Namespace prefixes may be an empty sequence. In fact, if the namespace URI is an empty string, the prefix must be an empty sequence.


Using the Namespace Axis - Because the namespace axis is deprecated in XPath 2.0, the information held in namespace nodes is instead made available to applications using two functions: get-in-scope-namespaces and get-namespace-uri-for-prefix.


The information in the data model stored for namespace nodes includes its base URI, its node kind (which returns "namespace" here), its node name (which returns a qualified name with the namespace prefix and an empty URI), its parent node, and its string value (which is the namespace URI of the node).

Processing Instruction Nodes

In XPath 2.0, processing instruction nodes encapsulate XML processing instructions. Processing instructions have these properties:

  • target

  • content

  • base-uri

  • parent

Included in the information the XPath 2.0 data model stores for processing instructions is its base URI, node kind (returns "processing-instruction"), node name (returns a qualified name with the processing-instruction target in the local-name and an empty URI), its parent, its string value (the content of the processing-instruction), and its typed value (which is the string value of the processing-instruction).

Comment Nodes

Comment nodes encapsulate XML comments. Comments have these properties:

  • content

  • parent

Included in the information the XPath 2.0 data model stores for comments is the base URI of the comment's parent, its node kind (which returns "comment" here), its parent, its string value, and its typed value (which is just the string value of the comment).

Text Nodes

Text nodes encapsulate XML character content. Text nodes have these properties in the XPath 2.0 data model:

  • content

  • parent

In XPath 2.0, text nodes cannot contain the empty string as its content, and document and element nodes impose the constraint that two consecutive text nodes can never occur as adjacent siblings.

Included in the information the XPath 2.0 data model stores for text nodes are the base URI of the node's parent, the node kind (which returns "text") here, the parent element or document node, and its string value (which is just the content of the text node).

Atomic Values

As opposed to nodes, atomic values correspond to the primitive simple types defined by the XML Schema specification, or values whose types are derived from them by restriction in a schema. Here are the primitive simple types as predefined in the XML schema specification—the xs namespace corresponds to "http://www.w3.org/2001/XMLSchema":

  • xs:string

  • xs:boolean

  • xs:decimal

  • xs:float

  • xs:double

  • xs:duration

  • xs:dateTime

  • xs:time

  • xs:date

  • xs:gYearMonth

  • xs:gYear

  • xs:gMonthDay

  • xs:gDay

  • xs:gMonth

  • xs:hexBinary

  • xs:base64Binary

  • xs:anyURI

  • xs:QName

  • xs:NOTATION


More on Primitive Types - For more on the primitive simple types built into XML schema, see http://www.w3.org/TR/xmlschema-2.


Along with the primitive simple types, types that are derived from them (including by the user) by restriction are considered atomic types in the XPath 2.0 data model. You use the <restriction> element in an XML schema to derive this kind of a type and restrict the types of values it can take.

In the following example, we're declaring a derived and restricted type named StateAbbreviation, and using a <pattern> element to restrict it to two-character strings like AZ or CA:

<simpleType name='StateAbbreviation'>
  <restriction base='xs:string'>
   <pattern value='[A-Z]{2}'/>
  </restriction>
</simpleType>




Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel