Record Class XPathResult
java.lang.Object
java.lang.Record
cloud.opencode.base.xml.xpath.XPathResult
- Record Components:
value- the raw result value | 原始结果值elements- the list of element results | 元素结果列表xpath- the XPath expression used | 使用的 XPath 表达式Features | 主要功能:
- Container for XPath query results - XPath 查询结果的容器
- Access results as string, number, boolean, or element list - 以字符串、数字、布尔值或元素列表访问结果
- Immutable record type - 不可变记录类型
Usage Examples | 使用示例:
// Access XPath result XPathResult result = OpenXPath.evaluate(doc, "//user/name"); String name = result.asString(); List<XmlElement> elements = result.elements();Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (value can be null) - 空值安全: 是(值可以为 null)
XPath Result - Container for XPath query results
XPath 结果 - XPath 查询结果的容器
This record holds the result of an XPath query with convenience methods for accessing the result in different forms.
此记录保存 XPath 查询的结果,并提供便捷方法以不同形式访问结果。
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionXPathResult(Object value, List<XmlElement> elements, String xpath) Creates an instance of aXPathResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the result as a boolean.asDouble()Returns the result as a double.Returns the first element if available.Returns all elements.asInt()Returns the result as an integer.asLong()Returns the result as a long.Returns the result as an optional integer.Returns the result as an optional string.asString()Returns the result as a string.intcount()Returns the count of matched elements.elements()Returns the value of theelementsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Returns whether the result is empty.static XPathResultCreates an XPath result from a single value.static XPathResultof(List<XmlElement> elements, String xpath) Creates an XPath result from elements.final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.xpath()Returns the value of thexpathrecord component.
-
Constructor Details
-
XPathResult
-
-
Method Details
-
of
Creates an XPath result from a single value. 从单个值创建 XPath 结果。- Parameters:
value- the value | 值xpath- the XPath expression | XPath 表达式- Returns:
- the result | 结果
-
of
Creates an XPath result from elements. 从元素创建 XPath 结果。- Parameters:
elements- the elements | 元素列表xpath- the XPath expression | XPath 表达式- Returns:
- the result | 结果
-
asString
-
asOptionalString
-
asInt
-
asOptionalInt
-
asLong
-
asDouble
Returns the result as a double. 返回结果为双精度浮点数。- Returns:
- the double value | 双精度浮点数值
-
asBoolean
Returns the result as a boolean. 返回结果为布尔值。- Returns:
- the boolean value | 布尔值
-
asElement
Returns the first element if available. 返回第一个元素(如果可用)。- Returns:
- the first element | 第一个元素
-
asElements
-
isEmpty
public boolean isEmpty()Returns whether the result is empty. 返回结果是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
count
public int count()Returns the count of matched elements. 返回匹配元素的数量。- Returns:
- the count | 数量
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
value
-
elements
-
xpath
-