Package org.simpleframework.xml.core
Interface Expression
- All Known Implementing Classes:
EmptyExpression
,PathParser
,PathParser.PathSection
The
Expression
interface is used to represent an XPath
expression. Any element or attribute may be defined as having an
XPath expression so that it may be located within an XML document.
This provides a convenient interface to navigating structures
based on an XPath expression. The below formats are supported.
./example/path ./example[2]/path/ example/path example/path/@attribute ./path/@attributeAs can be seen only a subset of the XPath syntax is supported by this. For convenience this provides a means to acquire paths from within a path, which makes a single expression more useful when navigating structures representing the XML document.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(String name) This is used to acquire the attribute path using this XPath expression.getElement
(String name) This is used to acquire the element path using this XPath expression.getFirst()
This can be used to acquire the first path segment within the expression.int
getIndex()
If the first path segment contains an index it is provided by this method.getLast()
This can be used to acquire the last path segment within the expression.getPath()
This location contains the full path expression with all of the indexes explicitly shown for each path segment.getPath
(int from) This allows an expression to be extracted from the current context.getPath
(int from, int trim) This allows an expression to be extracted from the current context.This is used to extract a namespace prefix from the path expression.boolean
This is used to determine if the expression points to an attribute value.boolean
isEmpty()
This method is used to determine if this expression is an empty path.boolean
isPath()
This is used to determine if the expression is a path.toString()
Provides a canonical XPath expression.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getIndex
int getIndex()If the first path segment contains an index it is provided by this method. There may be several indexes within a path, however only the index at the first segment is issued by this method. If there is no index this will return 1.- Returns:
- this returns the index of this path expression
-
getPrefix
String getPrefix()This is used to extract a namespace prefix from the path expression. A prefix is used to qualify the XML element name and does not form part of the actual path structure. This can be used to add the namespace in addition to the name.- Returns:
- this returns the prefix for the path expression
-
getFirst
String getFirst()This can be used to acquire the first path segment within the expression. The first segment represents the parent XML element of the path. All segments returned do not contain any slashes and so represents the real element name.- Returns:
- this returns the parent element for the path
-
getLast
String getLast()This can be used to acquire the last path segment within the expression. The last segment represents the leaf XML element of the path. All segments returned do not contain any slashes and so represents the real element name.- Returns:
- this returns the leaf element for the path
-
getPath
String getPath()This location contains the full path expression with all of the indexes explicitly shown for each path segment. This is used to create a uniform representation that can be used for comparisons of different path expressions.- Returns:
- this returns an expanded version of the path
-
getElement
This is used to acquire the element path using this XPath expression. The element path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.- Parameters:
name
- this is the name of the element to be used- Returns:
- a fully qualified path for the specified name
-
getAttribute
This is used to acquire the attribute path using this XPath expression. The attribute path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.- Parameters:
name
- this is the name of the attribute to be used- Returns:
- a fully qualified path for the specified name
-
getPath
This allows an expression to be extracted from the current context. Extracting expressions in this manner makes it more convenient for navigating structures representing the XML document. If an expression can not be extracted with the given criteria an exception will be thrown.- Parameters:
from
- this is the number of segments to skip to- Returns:
- this returns an expression from this one
-
getPath
This allows an expression to be extracted from the current context. Extracting expressions in this manner makes it more convenient for navigating structures representing the XML document. If an expression can not be extracted with the given criteria an exception will be thrown.- Parameters:
from
- this is the number of segments to skip totrim
- the number of segments to trim from the end- Returns:
- this returns an expression from this one
-
isAttribute
boolean isAttribute()This is used to determine if the expression points to an attribute value. An attribute value contains an '@' character before the last segment name. Such expressions distinguish element references from attribute references.- Returns:
- this returns true if the path has an attribute
-
isPath
boolean isPath()This is used to determine if the expression is a path. An expression represents a path if it contains more than one segment. If only one segment exists it is an element name.- Returns:
- true if this contains more than one segment
-
isEmpty
boolean isEmpty()This method is used to determine if this expression is an empty path. An empty path can be represented by a single period, '.'. It identifies the current path.- Returns:
- returns true if this represents an empty path
-
toString
String toString()Provides a canonical XPath expression. This is used for both debugging and reporting. The path returned represents the original path that has been parsed to form the expression.
-