Package net.jodah.xsylum
Class XmlSearchable<T>
- java.lang.Object
-
- net.jodah.xsylum.XmlSearchable<T>
-
- Type Parameters:
T
- source type
- Direct Known Subclasses:
XmlDocument
,XmlElement
public abstract class XmlSearchable<T> extends Object
An XPath searchable XML object.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description XmlElement
find(String expression)
Returns the first element matching theexpression
, else null if none can be found.List<XmlElement>
findAll(String expression)
Returns all elements that match theexpression
, else empty list if none can be found.abstract XmlElement
get(String tagName)
Returns the first child element that matches thetagName
, else null.abstract List<XmlElement>
getAll(String tagName)
Returns all child elements that match thetagName
else empty List.String
value(String expression)
Finds the value for the XPathexpression
.boolean
valueAsBoolean(String expression)
Finds the value for the XPathexpression
as a boolean.double
valueAsDouble(String expression)
Finds the value for the XPathexpression
as a double.<V extends Enum<V>>
VvalueAsEnum(String expression, Class<V> targetEnum)
Finds the value for the XPathexpression
as an Enum of typeV
.int
valueAsInt(String expression)
Finds the value for the XPathexpression
as an integer.long
valueAsLong(String expression)
Finds the value for the XPathexpression
as a long.List<String>
values(String expression)
Finds the values for the XPathexpression
.List<Boolean>
valuesAsBoolean(String expression)
Finds the values for the XPathexpression
as booleans.List<Double>
valuesAsDouble(String expression)
Finds the values for the XPathexpression
as doubles.<V extends Enum<V>>
List<V>valuesAsEnum(String expression, Class<V> targetEnum)
Finds the values for the XPathexpression
as Enums of typeV
.List<Integer>
valuesAsInt(String expression)
Finds the values for the XPathexpression
as integers.List<Long>
valuesAsLong(String expression)
Finds the values for the XPathexpression
ending in text() as longs.
-
-
-
Field Detail
-
source
protected final T source
-
-
Method Detail
-
find
public XmlElement find(String expression) throws XPathExpressionException
Returns the first element matching theexpression
, else null if none can be found.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
findAll
public List<XmlElement> findAll(String expression) throws XPathExpressionException
Returns all elements that match theexpression
, else empty list if none can be found.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
get
public abstract XmlElement get(String tagName)
Returns the first child element that matches thetagName
, else null.
-
getAll
public abstract List<XmlElement> getAll(String tagName)
Returns all child elements that match thetagName
else empty List.
-
value
public String value(String expression) throws XPathExpressionException
Finds the value for the XPathexpression
.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valueAsBoolean
public boolean valueAsBoolean(String expression) throws XPathExpressionException
Finds the value for the XPathexpression
as a boolean. Returns true for "true", "1", "yes", "y" ignoring case, else returns false.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valueAsDouble
public double valueAsDouble(String expression) throws XPathExpressionException
Finds the value for the XPathexpression
as a double.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the value for the expression is not a valid double
-
valueAsEnum
public <V extends Enum<V>> V valueAsEnum(String expression, Class<V> targetEnum) throws XPathExpressionException
Finds the value for the XPathexpression
as an Enum of typeV
. Returns null if value cannot be parsed to an Enum of typeV
.- Type Parameters:
V
- enum type- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valueAsInt
public int valueAsInt(String expression) throws XPathExpressionException
Finds the value for the XPathexpression
as an integer.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the value for the expression is not a valid int
-
valueAsLong
public long valueAsLong(String expression) throws XPathExpressionException
Finds the value for the XPathexpression
as a long.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the value for the expression is not a valid long
-
values
public List<String> values(String expression) throws XPathExpressionException
Finds the values for the XPathexpression
.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valuesAsBoolean
public List<Boolean> valuesAsBoolean(String expression) throws XPathExpressionException
Finds the values for the XPathexpression
as booleans. Returns true for "true", "1", "yes", "y" ignoring case, else returns false.- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valuesAsDouble
public List<Double> valuesAsDouble(String expression) throws XPathExpressionException
Finds the values for the XPathexpression
as doubles.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the values for the expression are not valid doubles
-
valuesAsEnum
public <V extends Enum<V>> List<V> valuesAsEnum(String expression, Class<V> targetEnum) throws XPathExpressionException
Finds the values for the XPathexpression
as Enums of typeV
. Returns null for values that cannot be parsed to an Enum of typeV
.- Type Parameters:
V
- enum type- Throws:
XPathExpressionException
- if theexpression
is invalid
-
valuesAsInt
public List<Integer> valuesAsInt(String expression) throws XPathExpressionException
Finds the values for the XPathexpression
as integers.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the values for the expression are not valid ints
-
valuesAsLong
public List<Long> valuesAsLong(String expression) throws XPathExpressionException
Finds the values for the XPathexpression
ending in text() as longs.- Throws:
XPathExpressionException
- if theexpression
is invalidNumberFormatException
- if the values for the expression are not valid longs
-
-