-
- All Superinterfaces:
java.lang.Iterable<org.w3c.dom.Element>
public interface Match extends java.lang.Iterable<org.w3c.dom.Element>
A wrapper type forElement
This is the main type of the jOOX library. It wraps an ordered list of DOM elements without duplicates and provides useful operations upon all of the contained elements. The wrapped DOM elements have been previously "matched" by a jOOX operation.
The API has been inspired by http://jquery.com, a fantastic DOM abstraction library for JavaScript.
- Author:
- Lukas Eder
- See Also:
- http://jquery.com
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Match
add(Match... elements)
Add some elements to the set of matched elementsMatch
add(org.w3c.dom.Element... elements)
Add some elements to the set of matched elementsMatch
after(java.lang.String content)
Add content after each element in the set of matched elements.Match
after(Content content)
Add content after each element in the set of matched elements.Match
after(Match... content)
Add content after each element in the set of matched elements.Match
after(org.w3c.dom.Element... content)
Add content after each element in the set of matched elements.Match
andSelf()
Add the previous set of matched elements to the current one.Match
append(java.lang.String content)
Append content to the end of each element's content in the set of matched elements.Match
append(Content content)
Append content to the end of each element's content in the set of matched elements.Match
append(Match... content)
Append content to the end of each element's content in the set of matched elements.Match
append(org.w3c.dom.Element... content)
Append content to the end of each element's content in the set of matched elements.java.lang.String
attr(java.lang.String name)
Get an attribute from the first element in the set of matched elements, ornull
if the first element does not have that attribute.<T> T
attr(java.lang.String name, java.lang.Class<T> type)
Get a converted attribute from the first element in the set of matched elements, ornull
if the first element does not have that attribute.Match
attr(java.lang.String name, java.lang.String value)
Set an attribute on all elements in the set of matched elements.Match
attr(java.lang.String name, Content value)
Set an attribute on all elements in the set of matched elements.java.util.List<java.lang.String>
attrs(java.lang.String name)
Get an attribute from all elements in the set of matched elements<T> java.util.List<T>
attrs(java.lang.String name, java.lang.Class<T> type)
Get a converted attribute from all elements in the set of matched elementsMatch
before(java.lang.String content)
Add content before each element in the set of matched elements.Match
before(Content content)
Add content before each element in the set of matched elements.Match
before(Match... content)
Add content before each element in the set of matched elements.Match
before(org.w3c.dom.Element... content)
Add content before each element in the set of matched elements.java.lang.String
cdata()
Get the CDATA content of the first element in the set of matched elements, ornull
if there are no matched elements.java.lang.String
cdata(int index)
Get the CDATA content at a given index in the current set of matched elements.<T> T
cdata(java.lang.Class<T> type)
Get the converted CDATA content of the first element in the set of matched elements, ornull
if there are no matched elements.Match
cdata(java.lang.String content)
Set some CDATA content to all elements in the set of matched elements (possibly replacing existing content).Match
cdata(Content content)
Set some CDATA content to all elements in the set of matched elements (possibly replacing existing content).java.util.List<java.lang.String>
cdatas()
Get all CDATA content of the elements in the set of matched elements.java.util.List<java.lang.String>
cdatas(int... indexes)
Get all CDATA content of the elements at given indexes in the set of matched elements.<T> java.util.List<T>
cdatas(java.lang.Class<T> type)
Get all converted CDATA content of the elements in the set of matched elements.Match
child()
Find the first child of each element in the current set of matched elements.Match
child(int index)
Find the child at a given index of each element in the current set of matched elements.Match
child(java.lang.String selector)
Find the first matching child of each element in the current set of matched elementsMatch
child(Filter filter)
Find the first matching child of each element in the current set of matched elementsMatch
children()
Find all children of each element in the current set of matched elements.Match
children(int... indexes)
Find all children of each element at given indexes in the current set of matched elements.Match
children(java.lang.String selector)
Find all children of each element in the current set of matched elements.Match
children(Filter filter)
Find all children of each element in the current set of matched elements.java.lang.String
content()
Get the XML content of the first element in the set of matched elements, ornull
if there are no matched elements.java.lang.String
content(int index)
Get the XML content at a given index in the current set of matched elements.Match
content(java.lang.Object content)
Add some JAXB-marshallable XML content to all elements in the set of matched elements (possibly replacing existing content).Match
content(java.lang.String content)
Add some XML content to all elements in the set of matched elements (possibly replacing existing content).Match
content(Content content)
Add some XML content to all elements in the set of matched elements (possibly replacing existing content).java.util.List<java.lang.String>
contents()
Get all XML content of the elements in the set of matched elements.java.util.List<java.lang.String>
contents(int... indexes)
Get all XML content of the elements at given indexes in the set of matched elements.Match
copy()
Get a copy of theMatch
wrapper.org.w3c.dom.Document
document()
Get the underlying document of the set of matched elements.java.util.List<Match>
each()
Get all elements in the set of matched elements in a list of matches, every match representing one elementMatch
each(java.lang.Iterable<? extends Each> each)
Execute several callbacks for every element in the current set of matched elements.Match
each(Each each)
Execute a callback for every element in the current set of matched elements.Match
each(Each... each)
Execute several callbacks for every element in the current set of matched elements.Match
empty()
Removes all content from all elements in the set of matched elements.Match
eq(int... indexes)
Reduce the current set of matched elements to the elements at the given indexes.Match
filter(java.lang.String selector)
Reduce the current set of matched elements.Match
filter(Filter filter)
Reduce the current set of matched elements.Match
find()
Find all descendants of each element in the current set of matched elements.Match
find(java.lang.String selector)
Find all descendants of each element in the current set of matched elements.Match
find(Filter filter)
Find all descendants of each element in the current set of matched elements.Match
first()
Get the first in a set of matched elements.java.util.List<org.w3c.dom.Element>
get()
Get an the set of matched elementsorg.w3c.dom.Element
get(int index)
Get an element from the set of matched elements at a given indexjava.util.List<org.w3c.dom.Element>
get(int... indexes)
Get some elements from the set of matched elements at the given indexesMatch
has(java.lang.String selector)
Reduce the set of matched element to those who have a descendant that matches a selector.Match
has(Filter filter)
Reduce the set of matched element to those who have a descendant that matches a filter.java.lang.String
id()
Get the first id valuejava.lang.String
id(int index)
Get an id value at a given index in the current set of matched elements.<T> T
id(java.lang.Class<T> type)
Get the first converted id valuejava.util.List<java.lang.String>
ids()
Get a list of id values in the current set of matched elements.java.util.List<java.lang.String>
ids(int... indexes)
Get a list of id values at given indexes in the current set of matched elements.<T> java.util.List<T>
ids(java.lang.Class<T> type)
Get a list of converted id values in the current set of matched elements.boolean
is(java.lang.String selector)
Check if at least one element in the set of matched elements satisfies a selector.boolean
is(Filter filter)
Check if at least one element in the set of matched elements satisfies a filter.boolean
isEmpty()
Whether there are any matched elements in the set of matched elementsboolean
isNotEmpty()
Whether there are any matched elements in the set of matched elementsMatch
last()
Get the last in a set of matched elements.Match
leaf()
Reduce the set of matched elements to the ones that are leaf elements<E> java.util.List<E>
map(Mapper<E> map)
Map the set of matched elements to a list of somethingMatch
matchAttr(java.lang.String name, java.lang.String valueRegex)
Reduce the set of matched elements by filtering out those whose attribute content doesn't match a given regexMatch
matchAttr(java.lang.String name, java.lang.String valueRegex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose attribute content doesn't match a given regex(keepMatches = true)
, or those whose text content matches a given regex(keepMatches = false)
Match
matchTag(java.lang.String regex)
Reduce the set of matched elements by filtering out those whose tag name doesn't match a given regexMatch
matchTag(java.lang.String regex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose tag name doesn't match a given regex(keepMatches = true)
, or those whose tag name matches a given regex(keepMatches = false)
Match
matchText(java.lang.String regex)
Reduce the set of matched elements by filtering out those whose text content doesn't match a given regexMatch
matchText(java.lang.String regex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose text content doesn't match a given regex(keepMatches = true)
, or those whose text content matches a given regex(keepMatches = false)
Match
namespace(java.lang.String namespacePrefix, java.lang.String namespaceURI)
Get a new Match with added namespace configuration for subsequent XPath callsjava.lang.String
namespacePrefix()
Get the namespace prefix of the first element in the current set of matched elements.java.lang.String
namespacePrefix(int index)
Get a namespace prefix of the element at a given index in the current set of matched elements.java.util.List<java.lang.String>
namespacePrefixes()
Get a list of namespace prefixes of the elements in the current set of matched elements.java.util.List<java.lang.String>
namespacePrefixes(int... indexes)
Get a list of namespace prefixes of the elements at given indexes in the current set of matched elements.Match
namespaces(java.util.Map<java.lang.String,java.lang.String> map)
Get a new Match with added namespace configuration for subsequent XPath callsjava.lang.String
namespaceURI()
Get the namespace URI of the first element in the current set of matched elements.java.lang.String
namespaceURI(int index)
Get a namespace URI of the element at a given index in the current set of matched elements.java.util.List<java.lang.String>
namespaceURIs()
Get a list of namespace URIs of the elements in the current set of matched elements.java.util.List<java.lang.String>
namespaceURIs(int... indexes)
Get a list of namespace URIs of the elements at given indexes in the current set of matched elements.Match
next()
Get the immediate next sibling of every element in set of matched elements.Match
next(java.lang.String selector)
Get the immediate next sibling of every element in set of matched elements, matching a selectorMatch
next(Filter filter)
Get the immediate next sibling of every element in set of matched elements, matching a filterMatch
nextAll()
Get all next siblings of every element in a set of matched elementsMatch
nextAll(java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selectorMatch
nextAll(Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filterMatch
nextUntil(java.lang.String until)
Get all next siblings of every element in a set of matched elements until the provided selector matchesMatch
nextUntil(java.lang.String until, java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selector, until the provided selector matchesMatch
nextUntil(java.lang.String until, Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filter, until the provided selector matchesMatch
nextUntil(Filter until)
Get all next siblings of every element in a set of matched elements until the provided filter matchesMatch
nextUntil(Filter until, java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selector until the provided filter matchesMatch
nextUntil(Filter until, Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filter until the provided filter matchesMatch
not(java.lang.String selector)
Remove elements from the set of matched elements.Match
not(Filter filter)
Remove elements from the set of matched elements.Match
parent()
Get the immediate parent elements of every element in a set of matched elementsMatch
parent(java.lang.String selector)
Get the immediate parent elements of every element in a set of matched elements, matching a selectorMatch
parent(Filter filter)
Get the immediate parent elements of every element in a set of matched elements, matching a filterMatch
parents()
Get all ancestor elements of every element in a set of matched elementsMatch
parents(java.lang.String selector)
Get all ancestor elements of every element in a set of matched elements, matching a selectorMatch
parents(Filter filter)
Get all ancestor elements of every element in a set of matched elements, matching a filterMatch
parentsUntil(java.lang.String until)
Get all ancestors of every element in a set of matched elements until the provided selector matchesMatch
parentsUntil(java.lang.String until, java.lang.String selector)
Get all ancestors of every element in a set of matched elements, matching a selector, until the provided selector matchesMatch
parentsUntil(java.lang.String until, Filter filter)
Get all ancestors of every element in a set of matched elements, matching a filter, until the provided selector matchesMatch
parentsUntil(Filter until)
Get all ancestors of every element in a set of matched elements until the provided filter matchesMatch
parentsUntil(Filter until, java.lang.String selector)
Get all ancestors of every element in a set of matched elements, matching a selector until the provided filter matchesMatch
parentsUntil(Filter until, Filter filter)
Get all ancestors of every element in a set of matched elements, matching a filter until the provided filter matchesMatch
prepend(java.lang.String content)
Prepend content to the beginning of each element's content in the set of matched elements.Match
prepend(Content content)
Prepend content to the beginning of each element's content in the set of matched elements.Match
prepend(Match... content)
Prepend content to the beginning of each element's content in the set of matched elements.Match
prepend(org.w3c.dom.Element... content)
Prepend content to the beginning of each element's content in the set of matched elements.Match
prev()
Get the immediate previous sibling of every element in set of matched elements.Match
prev(java.lang.String selector)
Get the immediate previous sibling of every element in set of matched elements, matching a selectorMatch
prev(Filter filter)
Get the immediate previous sibling of every element in set of matched elements, matching a filterMatch
prevAll()
Get all previous siblings of every element in a set of matched elementsMatch
prevAll(java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selectorMatch
prevAll(Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filterMatch
prevUntil(java.lang.String until)
Get all previous siblings of every element in a set of matched elements until the provided selector matchesMatch
prevUntil(java.lang.String until, java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selector, until the provided selector matchesMatch
prevUntil(java.lang.String until, Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filter, until the provided selector matchesMatch
prevUntil(Filter until)
Get all previous siblings of every element in a set of matched elements until the provided filter matchesMatch
prevUntil(Filter until, java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selector until the provided filter matchesMatch
prevUntil(Filter until, Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filter until the provided filter matchesMatch
remove()
Removes all elements from their parent nodes in the set of matched elements.Match
remove(java.lang.String selector)
Removes all elements from their parent nodes in the set of matched elements, matching a selectorMatch
remove(Filter filter)
Removes all elements from their parent nodes in the set of matched elements, matching a filterMatch
removeAttr(java.lang.String name)
Remove an attribute from all elements in the set of matched elements.Match
rename(java.lang.String tag)
Rename all tags in the set of matched elements to some new tag nameMatch
rename(Content tag)
Rename all tags in the set of matched elements to some new tag nameMatch
replaceWith(java.lang.String content)
Replace all elements in the set of matched elements with some new content.Match
replaceWith(Content content)
Replace all elements in the set of matched elements with some new content.Match
replaceWith(Match... content)
Replace all elements in the set of matched elements with some new content.Match
replaceWith(org.w3c.dom.Element... content)
Replace all elements in the set of matched elements with some new content.Match
reverse()
Reverse the order of the set of matched elementsMatch
siblings()
Get all siblings of every element in a set of matched elementsMatch
siblings(java.lang.String selector)
Get all siblings of every element in a set of matched elements, matching a selectorMatch
siblings(Filter filter)
Get all siblings of every element in a set of matched elements, matching a filterint
size()
Get the number of matched elements in the set of matched elementsMatch
slice(int start)
Reduce the set of matched elements by specifying a range of indexesMatch
slice(int start, int end)
Reduce the set of matched elements by specifying a range of indexesMatch
sort(java.util.Comparator<org.w3c.dom.Element> comparator)
Allows to sort the result with the given comparator.java.lang.String
tag()
Get the tag name of the first element in the current set of matched elements.java.lang.String
tag(int index)
Get a tag name of the element at a given index in the current set of matched elements.java.util.List<java.lang.String>
tags()
Get a list of tag names of the elements in the current set of matched elements.java.util.List<java.lang.String>
tags(int... indexes)
Get a list of tag names of the elements at given indexes in the current set of matched elements.java.lang.String
text()
Get the text content of the first element in the set of matched elements, ornull
if there are no matched elements.java.lang.String
text(int index)
Get the text content at a given index in the current set of matched elements.<T> T
text(java.lang.Class<T> type)
Get the converted text content of the first element in the set of matched elements, ornull
if there are no matched elements.Match
text(java.lang.String content)
Set some text content to all elements in the set of matched elements (possibly replacing existing content).Match
text(Content content)
Set some text content to all elements in the set of matched elements (possibly replacing existing content).java.util.List<java.lang.String>
texts()
Get all text content of the elements in the set of matched elements.java.util.List<java.lang.String>
texts(int... indexes)
Get all text content of the elements at given indexes in the set of matched elements.<T> java.util.List<T>
texts(java.lang.Class<T> type)
Get all converted text content of the elements in the set of matched elements.Match
transform(java.io.File transformer)
Transform all elements in the set of matched elements.Match
transform(java.io.InputStream transformer)
Transform all elements in the set of matched elements.Match
transform(java.io.Reader transformer)
Transform all elements in the set of matched elements.Match
transform(java.lang.String transformer)
Transform all elements in the set of matched elements.Match
transform(java.net.URL transformer)
Transform all elements in the set of matched elements.Match
transform(javax.xml.transform.Source transformer)
Transform all elements in the set of matched elements.Match
transform(javax.xml.transform.Transformer transformer)
Transform all elements in the set of matched elements.<T> java.util.List<T>
unmarshal(java.lang.Class<T> type)
Unmarshal the current set of matched elements into a JAXB-annotated type.<T> java.util.List<T>
unmarshal(java.lang.Class<T> type, int... indexes)
Unmarshal the current set of matched elements at given indexes into a JAXB-annotated type.<T> T
unmarshalOne(java.lang.Class<T> type)
Unmarshal the first element in the current set of matched elements into a JAXB-annotated type.<T> T
unmarshalOne(java.lang.Class<T> type, int index)
Unmarshal the element at a given index in the current set of matched elements into a JAXB-annotated type.Match
unwrap()
Removes all elements in the set of matched elements from their parentsMatch
wrap(java.lang.String parent)
Wrap all elements from their parent nodes in the set of matched elements in a new parent elementMatch
wrap(Content parent)
Wrap all elements in the set of matched elements in a new parent elementMatch
write(java.io.File file)
Write the set of matched elements into a fileMatch
write(java.io.OutputStream stream)
Write the set of matched elements into a streamMatch
write(java.io.Writer writer)
Write the set of matched elements into a writerjava.lang.String
xpath()
Get an XPath expression describing the first element in the current set of matched elementsjava.lang.String
xpath(int index)
Get an XPath expression describing the element at a given index in the current set of matched elementsMatch
xpath(java.lang.String expression)
Match all elements given a certain XPath expression applied to each element in the current set of matched elements.Match
xpath(java.lang.String expression, java.lang.Object... variables)
Match all elements given a certain XPath expression applied to each element in the current set of matched elements.java.util.List<java.lang.String>
xpaths()
Get a list of XPath expressions describing the elements in the current set of matched elementsjava.util.List<java.lang.String>
xpaths(int... indexes)
Get a list of XPath expressions describing the elements at the given indexes in the current set of matched elements
-
-
-
Method Detail
-
namespace
Match namespace(java.lang.String namespacePrefix, java.lang.String namespaceURI)
Get a new Match with added namespace configuration for subsequent XPath callsThis is a convenience method for
namespaces(java.util.Map)
- Parameters:
namespacePrefix
- A namespace prefixnamespaceURI
- A namespace URI- Returns:
- A modified
Match
- See Also:
namespaces(Map)
-
namespaces
Match namespaces(java.util.Map<java.lang.String,java.lang.String> map)
Get a new Match with added namespace configuration for subsequent XPath calls- Parameters:
map
- A mapping between prefix and namespace URI- Returns:
- A modified
Match
-
namespaceURIs
java.util.List<java.lang.String> namespaceURIs()
Get a list of namespace URIs of the elements in the current set of matched elements.This only works if the underlying document is namespace-aware
- See Also:
Node.getNamespaceURI()
-
namespaceURIs
java.util.List<java.lang.String> namespaceURIs(int... indexes)
Get a list of namespace URIs of the elements at given indexes in the current set of matched elements.This only works if the underlying document is namespace-aware
- See Also:
Node.getNamespaceURI()
-
namespaceURI
java.lang.String namespaceURI()
Get the namespace URI of the first element in the current set of matched elements.This is the same as calling
namespaceURI(0)
This only works if the underlying document is namespace-aware
- See Also:
Node.getNamespaceURI()
-
namespaceURI
java.lang.String namespaceURI(int index)
Get a namespace URI of the element at a given index in the current set of matched elements.This only works if the underlying document is namespace-aware
- See Also:
Node.getNamespaceURI()
-
namespacePrefixes
java.util.List<java.lang.String> namespacePrefixes()
Get a list of namespace prefixes of the elements in the current set of matched elements.
-
namespacePrefixes
java.util.List<java.lang.String> namespacePrefixes(int... indexes)
Get a list of namespace prefixes of the elements at given indexes in the current set of matched elements.
-
namespacePrefix
java.lang.String namespacePrefix()
Get the namespace prefix of the first element in the current set of matched elements.This is the same as calling
namespaceURI(0)
-
namespacePrefix
java.lang.String namespacePrefix(int index)
Get a namespace prefix of the element at a given index in the current set of matched elements.
-
get
org.w3c.dom.Element get(int index)
Get an element from the set of matched elements at a given indexNegative indexes are possible, too.
-
-1
corresponds to the last element in the set of matched elements. -
-2
corresponds to the second-last element, etc.
-
-
document
org.w3c.dom.Document document()
Get the underlying document of the set of matched elements.This will also return a document if there are no elements in the set of matched elements, either because a new document has been created previously, or the set of matched elements has been reduced to an empty set.
-
get
java.util.List<org.w3c.dom.Element> get(int... indexes)
Get some elements from the set of matched elements at the given indexesNegative indexes are possible, too.
-
-1
corresponds to the last element in the set of matched elements. -
-2
corresponds to the second-last element, etc.
-
-
get
java.util.List<org.w3c.dom.Element> get()
Get an the set of matched elements
-
size
int size()
Get the number of matched elements in the set of matched elements
-
isEmpty
boolean isEmpty()
Whether there are any matched elements in the set of matched elements
-
isNotEmpty
boolean isNotEmpty()
Whether there are any matched elements in the set of matched elements
-
add
Match add(org.w3c.dom.Element... elements)
Add some elements to the set of matched elements
-
reverse
Match reverse()
Reverse the order of the set of matched elements
-
andSelf
Match andSelf()
Add the previous set of matched elements to the current one. This works after any of these methods (including all overloaded variants):child()
children()
find()
next()
nextAll()
nextUntil(Filter)
parent()
parents()
parentsUntil(Filter)
prev()
prevAll()
prevUntil(Filter)
siblings()
eq(int...)
, and then add the removed elements again, usingandSelf()
.
-
child
Match child()
Find the first child of each element in the current set of matched elements.This is the same as calling
child(0)
.
-
child
Match child(java.lang.String selector)
Find the first matching child of each element in the current set of matched elementsThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
child
Match child(Filter filter)
Find the first matching child of each element in the current set of matched elements
-
child
Match child(int index)
Find the child at a given index of each element in the current set of matched elements.
-
children
Match children()
Find all children of each element in the current set of matched elements.
-
children
Match children(java.lang.String selector)
Find all children of each element in the current set of matched elements.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
children
Match children(Filter filter)
Find all children of each element in the current set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element whose children are searched -
Context.matchIndex()
- the index of the matched element whose children are searched -
Context.element()
- the child candidate that is being filtered -
Context.elementIndex()
- the index within its parent of the child candidate that is being filtered
-
-
children
Match children(int... indexes)
Find all children of each element at given indexes in the current set of matched elements.
-
each
java.util.List<Match> each()
Get all elements in the set of matched elements in a list of matches, every match representing one element
-
each
Match each(Each each)
Execute a callback for every element in the current set of matched elements.
-
each
Match each(Each... each)
Execute several callbacks for every element in the current set of matched elements.- See Also:
JOOX.chain(Each...)
-
each
Match each(java.lang.Iterable<? extends Each> each)
Execute several callbacks for every element in the current set of matched elements.- See Also:
JOOX.chain(Iterable)
-
filter
Match filter(java.lang.String selector)
Reduce the current set of matched elements.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
filter
Match filter(Filter filter)
Reduce the current set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being filtered -
Context.matchIndex()
- the index of the matched element being filtered
-
-
eq
Match eq(int... indexes)
Reduce the current set of matched elements to the elements at the given indexes. If the given indexes are not in the range of indexes, the resulting set will be empty.Negative indexes are possible, too.
-
-1
corresponds to the last element in the set of matched elements. -
-2
corresponds to the second-last element, etc.
-
-
find
Match find()
Find all descendants of each element in the current set of matched elements.
-
find
Match find(java.lang.String selector)
Find all descendants of each element in the current set of matched elements.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
Tag names are namespace-unaware. This means that existing namespaces will be ignored - CSS selectors can be used to select XML elements
using XPath (see
CSS2XPath.css2xpath(String)
)
- XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
find
Match find(Filter filter)
Find all descendants of each element in the current set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element whose descendants are searched -
Context.matchIndex()
- the index of the matched element whose descendants are searched -
Context.element()
- the descendant candidate that is being filtered -
Context.elementIndex()
- the iteration index of the descendant candidate that is being filtered
-
-
xpath
Match xpath(java.lang.String expression)
Match all elements given a certain XPath expression applied to each element in the current set of matched elements.The XPath expression is evaluated using standard
XPath
. It must not contain any variables. Usexpath(String, Object...)
instead, if you wish to use variables. Note that only matched elements will be considered in the results. You cannot match attributes or text nodes, for instance. Examples:- Match all elements :
xpath("//*")
- Match all books :
xpath("/library/books/book")
- Match all book ID's :
xpath("//book").ids()
- Match all book names :
xpath("//book/name").texts()
- Match all book ID's :
xpath("//book/@id")
- Match all book names :
xpath("//book/name/text()")
Using jOOX with Namespaces
Namespace declarations are supported in XPath expressions. If you wish to use namespace-specific XPath elements, call
namespace(String, String)
prior toxpath(String)
Using jOOX with Xalan
If Xalan is on your classpath, jOOX will automatically load xalan's namespace and function extensions. All functionality supported by http://exslt.org will be available in your XPath expressions. Some examples:
- Match the book with the highest ID :
xpath("//book[number(@id) = math:max(//book/@id)]")
- Match books written by Orwell :
xpath("//book[java:org.joox.test.Functions.byOrwellWithNodes(.)]
- Match all elements :
-
xpath
Match xpath(java.lang.String expression, java.lang.Object... variables)
Match all elements given a certain XPath expression applied to each element in the current set of matched elements.The XPath expression is evaluated using standard
XPath
. It may contain numerical variables, declared as$1
,$2
, etc, starting with$1
. Other variables, such as$myVar
are not supported. You must provide at least one variable in thevariables
argument for every variable index. Note that only matched elements will be considered in the results. You cannot match attributes or text nodes, for instance. Examples:- Match all elements with id greater than 5:
xpath("//*[@id > $1]", 5)
- Match all books with more than two authors and one author is
"George Orwell" :
xpath("/library/books/book[count(authors/author) > $1][authors/author[text() = $2]]", 2, "George Orwell")
- Match all book ID's :
xpath("//book/@id")
- Match all book names :
xpath("//book/name/text()")
Using jOOX with Namespaces
Namespace declarations are supported in XPath expressions. If you wish to use namespace-specific XPath elements, call
namespace(String, String)
prior toxpath(String)
Using jOOX with Xalan
If Xalan is on your classpath, jOOX will automatically load xalan's namespace and function extensions. All functionality supported by http://exslt.org will be available in your XPath expressions. Some examples:
- Match the book with the highest ID :
xpath("//book[number(@id) = math:max(//book/@id)]")
- Match books written by Orwell :
xpath("//book[java:org.joox.test.Functions.byOrwellWithNodes(.)]
- Match all elements with id greater than 5:
-
first
Match first()
Get the first in a set of matched elements.
-
has
Match has(java.lang.String selector)
Reduce the set of matched element to those who have a descendant that matches a selector.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
has
Match has(Filter filter)
Reduce the set of matched element to those who have a descendant that matches a filter.The callback
Context
is populated like this:-
Context.match()
- the matched element whose descendants are searched -
Context.matchIndex()
- the index of the matched element whose descendants are searched -
Context.element()
- the descendant candidate that is being filtered -
Context.elementIndex()
- the iteration index of the descendant candidate that is being filtered
-
-
is
boolean is(java.lang.String selector)
Check if at least one element in the set of matched elements satisfies a selector.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
is
boolean is(Filter filter)
Check if at least one element in the set of matched elements satisfies a filter.The callback
Context
is populated like this:-
Context.match()
- the matched element being checked -
Context.matchIndex()
- the index of the matched element being checked
-
-
last
Match last()
Get the last in a set of matched elements.
-
map
<E> java.util.List<E> map(Mapper<E> map)
Map the set of matched elements to a list of something
-
next
Match next()
Get the immediate next sibling of every element in set of matched elements.
-
next
Match next(java.lang.String selector)
Get the immediate next sibling of every element in set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
next
Match next(Filter filter)
Get the immediate next sibling of every element in set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next sibling is searched -
Context.matchIndex()
- the index of the matched element whose next sibling is searched -
Context.element()
- the next sibling that is being filtered -
Context.elementIndex()
- 1
-
-
nextAll
Match nextAll()
Get all next siblings of every element in a set of matched elements
-
nextAll
Match nextAll(java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
nextAll
Match nextAll(Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next siblings are searched -
Context.matchIndex()
- the index of the matched element whose next siblings are searched -
Context.element()
- the next siblings that is being filtered -
Context.elementIndex()
- the relative index of the next siblings that are being filtered
-
-
nextUntil
Match nextUntil(java.lang.String until)
Get all next siblings of every element in a set of matched elements until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
nextUntil
Match nextUntil(Filter until)
Get all next siblings of every element in a set of matched elements until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next siblings are searched -
Context.matchIndex()
- the index of the matched element whose next siblings are searched -
Context.element()
- the next siblings that is being filtered -
Context.elementIndex()
- the relative index of the next siblings that are being filtered
-
-
nextUntil
Match nextUntil(java.lang.String until, java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selector, until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
nextUntil
Match nextUntil(java.lang.String until, Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filter, until the provided selector matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next siblings are searched -
Context.matchIndex()
- the index of the matched element whose next siblings are searched -
Context.element()
- the next siblings that is being filtered -
Context.elementIndex()
- the relative index of the next siblings that are being filtered
- See Also:
JOOX.selector(String)
-
-
nextUntil
Match nextUntil(Filter until, java.lang.String selector)
Get all next siblings of every element in a set of matched elements, matching a selector until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next siblings are searched -
Context.matchIndex()
- the index of the matched element whose next siblings are searched -
Context.element()
- the next siblings that is being filtered -
Context.elementIndex()
- the relative index of the next siblings that are being filtered
- See Also:
JOOX.selector(String)
-
-
nextUntil
Match nextUntil(Filter until, Filter filter)
Get all next siblings of every element in a set of matched elements, matching a filter until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose next siblings are searched -
Context.matchIndex()
- the index of the matched element whose next siblings are searched -
Context.element()
- the next siblings that is being filtered -
Context.elementIndex()
- the relative index of the next siblings that are being filtered
- See Also:
JOOX.selector(String)
-
-
not
Match not(java.lang.String selector)
Remove elements from the set of matched elements.The selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
not
Match not(Filter filter)
Remove elements from the set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being checked -
Context.matchIndex()
- the index of the matched element being checked
-
-
parent
Match parent()
Get the immediate parent elements of every element in a set of matched elements
-
parent
Match parent(java.lang.String selector)
Get the immediate parent elements of every element in a set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
parent
Match parent(Filter filter)
Get the immediate parent elements of every element in a set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parent is searched -
Context.matchIndex()
- the index of the matched element whose parent is searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- 1
-
-
parents
Match parents()
Get all ancestor elements of every element in a set of matched elements
-
parents
Match parents(java.lang.String selector)
Get all ancestor elements of every element in a set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
parents
Match parents(Filter filter)
Get all ancestor elements of every element in a set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parents are searched -
Context.matchIndex()
- the index of the matched element whose parents are searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- the relative index of the parent that is being filtered
-
-
parentsUntil
Match parentsUntil(java.lang.String until)
Get all ancestors of every element in a set of matched elements until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
parentsUntil
Match parentsUntil(Filter until)
Get all ancestors of every element in a set of matched elements until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parents are searched -
Context.matchIndex()
- the index of the matched element whose parents are searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- the relative index of the parent that is being filtered
-
-
parentsUntil
Match parentsUntil(java.lang.String until, java.lang.String selector)
Get all ancestors of every element in a set of matched elements, matching a selector, until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
parentsUntil
Match parentsUntil(java.lang.String until, Filter filter)
Get all ancestors of every element in a set of matched elements, matching a filter, until the provided selector matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parents are searched -
Context.matchIndex()
- the index of the matched element whose parents are searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- the relative index of the parent that is being filtered
- See Also:
JOOX.selector(String)
-
-
parentsUntil
Match parentsUntil(Filter until, java.lang.String selector)
Get all ancestors of every element in a set of matched elements, matching a selector until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parents are searched -
Context.matchIndex()
- the index of the matched element whose parents are searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- the relative index of the parent that is being filtered
- See Also:
JOOX.selector(String)
-
-
parentsUntil
Match parentsUntil(Filter until, Filter filter)
Get all ancestors of every element in a set of matched elements, matching a filter until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose parents are searched -
Context.matchIndex()
- the index of the matched element whose parents are searched -
Context.element()
- the parent that is being filtered -
Context.elementIndex()
- the relative index of the parent that is being filtered
-
-
prev
Match prev()
Get the immediate previous sibling of every element in set of matched elements.
-
prev
Match prev(java.lang.String selector)
Get the immediate previous sibling of every element in set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
prev
Match prev(Filter filter)
Get the immediate previous sibling of every element in set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous sibling is searched -
Context.matchIndex()
- the index of the matched element whose previous sibling is searched -
Context.element()
- the previous sibling that is being filtered -
Context.elementIndex()
- 1
-
-
prevAll
Match prevAll()
Get all previous siblings of every element in a set of matched elements
-
prevAll
Match prevAll(java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
prevAll
Match prevAll(Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous siblings are searched -
Context.matchIndex()
- the index of the matched element whose previous siblings are searched -
Context.element()
- the previous siblings that is being filtered -
Context.elementIndex()
- the relative index of the previous siblings that are being filtered
-
-
prevUntil
Match prevUntil(java.lang.String until)
Get all previous siblings of every element in a set of matched elements until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
prevUntil
Match prevUntil(Filter until)
Get all previous siblings of every element in a set of matched elements until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous siblings are searched -
Context.matchIndex()
- the index of the matched element whose previous siblings are searched -
Context.element()
- the previous siblings that is being filtered -
Context.elementIndex()
- the relative index of the previous siblings that are being filtered
-
-
prevUntil
Match prevUntil(java.lang.String until, java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selector, until the provided selector matchesThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
prevUntil
Match prevUntil(java.lang.String until, Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filter, until the provided selector matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous siblings are searched -
Context.matchIndex()
- the index of the matched element whose previous siblings are searched -
Context.element()
- the previous siblings that is being filtered -
Context.elementIndex()
- the relative index of the previous siblings that are being filtered
- See Also:
JOOX.selector(String)
-
-
prevUntil
Match prevUntil(Filter until, java.lang.String selector)
Get all previous siblings of every element in a set of matched elements, matching a selector until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous siblings are searched -
Context.matchIndex()
- the index of the matched element whose previous siblings are searched -
Context.element()
- the previous siblings that is being filtered -
Context.elementIndex()
- the relative index of the previous siblings that are being filtered
- See Also:
JOOX.selector(String)
-
-
prevUntil
Match prevUntil(Filter until, Filter filter)
Get all previous siblings of every element in a set of matched elements, matching a filter until the provided filter matchesThe callback
Context
is populated like this:-
Context.match()
- the matched element whose previous siblings are searched -
Context.matchIndex()
- the index of the matched element whose previous siblings are searched -
Context.element()
- the previous siblings that is being filtered -
Context.elementIndex()
- the relative index of the previous siblings that are being filtered
-
-
siblings
Match siblings()
Get all siblings of every element in a set of matched elements
-
siblings
Match siblings(java.lang.String selector)
Get all siblings of every element in a set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
siblings
Match siblings(Filter filter)
Get all siblings of every element in a set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element whose siblings are searched -
Context.matchIndex()
- the index of the matched element whose siblings are searched -
Context.element()
- the sibling that is being filtered -
Context.elementIndex()
- the relative index of the sibling that is being filtered. This is less than zero if it is a previous sibling or more than zero if it is a subsequent sibling, compared to the element inContext.match()
-
-
slice
Match slice(int start)
Reduce the set of matched elements by specifying a range of indexesThis is the same as calling
slice(start, Integer.MAX_VALUE)
-
slice
Match slice(int start, int end)
Reduce the set of matched elements by specifying a range of indexes
-
matchText
Match matchText(java.lang.String regex)
Reduce the set of matched elements by filtering out those whose text content doesn't match a given regexThis is the same as calling
matchText(regex, true)
- See Also:
JOOX.matchText(String)
-
matchText
Match matchText(java.lang.String regex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose text content doesn't match a given regex(keepMatches = true)
, or those whose text content matches a given regex(keepMatches = false)
- See Also:
JOOX.matchText(String)
-
matchAttr
Match matchAttr(java.lang.String name, java.lang.String valueRegex)
Reduce the set of matched elements by filtering out those whose attribute content doesn't match a given regexThis is the same as calling
matchAttr(name, valueRegex, true)
- See Also:
JOOX.matchAttr(String, String)
-
matchAttr
Match matchAttr(java.lang.String name, java.lang.String valueRegex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose attribute content doesn't match a given regex(keepMatches = true)
, or those whose text content matches a given regex(keepMatches = false)
- See Also:
JOOX.matchAttr(String, String)
-
matchTag
Match matchTag(java.lang.String regex)
Reduce the set of matched elements by filtering out those whose tag name doesn't match a given regexThis is the same as calling
matchText(regex, true)
- See Also:
JOOX.matchTag(String)
-
matchTag
Match matchTag(java.lang.String regex, boolean keepMatches)
Reduce the set of matched elements by filtering out those whose tag name doesn't match a given regex(keepMatches = true)
, or those whose tag name matches a given regex(keepMatches = false)
- See Also:
JOOX.matchTag(String)
-
leaf
Match leaf()
Reduce the set of matched elements to the ones that are leaf elements- See Also:
JOOX.leaf()
-
before
Match before(java.lang.String content)
Add content before each element in the set of matched elements.
-
before
Match before(Content content)
Add content before each element in the set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being prepended before -
Context.matchIndex()
- the index of the matched element being prepended before
-
-
before
Match before(Match... content)
Add content before each element in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
before
Match before(org.w3c.dom.Element... content)
Add content before each element in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
after
Match after(java.lang.String content)
Add content after each element in the set of matched elements.
-
after
Match after(Content content)
Add content after each element in the set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being appended after -
Context.matchIndex()
- the index of the matched element being appended after
-
-
after
Match after(Match... content)
Add content after each element in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
after
Match after(org.w3c.dom.Element... content)
Add content after each element in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
prepend
Match prepend(java.lang.String content)
Prepend content to the beginning of each element's content in the set of matched elements.
-
prepend
Match prepend(Content content)
Prepend content to the beginning of each element's content in the set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being prepended to -
Context.matchIndex()
- the index of the matched element being prepended to
-
-
prepend
Match prepend(Match... content)
Prepend content to the beginning of each element's content in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
prepend
Match prepend(org.w3c.dom.Element... content)
Prepend content to the beginning of each element's content in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
append
Match append(java.lang.String content)
Append content to the end of each element's content in the set of matched elements.
-
append
Match append(Content content)
Append content to the end of each element's content in the set of matched elements.The callback
Context
is populated like this:-
Context.match()
- the matched element being appended to -
Context.matchIndex()
- the index of the matched element being appended to
-
-
append
Match append(Match... content)
Append content to the end of each element's content in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
append
Match append(org.w3c.dom.Element... content)
Append content to the end of each element's content in the set of matched elements.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
replaceWith
Match replaceWith(java.lang.String content)
Replace all elements in the set of matched elements with some new content.
-
replaceWith
Match replaceWith(Content content)
Replace all elements in the set of matched elements with some new content.
-
replaceWith
Match replaceWith(Match... content)
Replace all elements in the set of matched elements with some new content.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
replaceWith
Match replaceWith(org.w3c.dom.Element... content)
Replace all elements in the set of matched elements with some new content.If the added content is already contained in this document, then it is moved. Otherwise, it is cloned. If there are several elements in the set of matched elements, then the added content is duplicated.
-
rename
Match rename(java.lang.String tag)
Rename all tags in the set of matched elements to some new tag name
-
rename
Match rename(Content tag)
Rename all tags in the set of matched elements to some new tag name
-
empty
Match empty()
Removes all content from all elements in the set of matched elements.
-
remove
Match remove()
Removes all elements from their parent nodes in the set of matched elements.
-
remove
Match remove(java.lang.String selector)
Removes all elements from their parent nodes in the set of matched elements, matching a selectorThe selector provided to this method supports the following features:
- * can be used to select everything
- tag names can be used to select XML elements by tag
names (see
Element.getElementsByTagName(String)
. Tag names are namespace-unaware. This means that existing namespaces will be ignored
- CSS selectors cannot be used (yet) to select XML
elements from this method. Use
find(String)
instead - XPath cannot be used. Use
xpath(String)
instead - Namespaces cannot be used. Use
xpath(String)
withnamespaces(Map)
instead
- See Also:
JOOX.selector(String)
-
remove
Match remove(Filter filter)
Removes all elements from their parent nodes in the set of matched elements, matching a filterThe callback
Context
is populated like this:-
Context.match()
- the matched element being removed -
Context.matchIndex()
- the index of the matched element being removed
-
-
wrap
Match wrap(java.lang.String parent)
Wrap all elements from their parent nodes in the set of matched elements in a new parent elementThe resulting set of matched elements contains the newly wrapped elements
- See Also:
unwrap()
-
wrap
Match wrap(Content parent)
Wrap all elements in the set of matched elements in a new parent elementThe resulting set of matched elements contains the newly wrapped elements
- See Also:
unwrap()
-
unwrap
Match unwrap()
Removes all elements in the set of matched elements from their parentsThe resulting set of matched elements contains the newly unwrapped elements
- See Also:
wrap(String)
-
attr
java.lang.String attr(java.lang.String name)
Get an attribute from the first element in the set of matched elements, ornull
if the first element does not have that attribute.jOOX is namespace-unaware. The supplied attribute name will be compared against all attributes, matching the first one that has the given name.
-
attr
<T> T attr(java.lang.String name, java.lang.Class<T> type)
Get a converted attribute from the first element in the set of matched elements, ornull
if the first element does not have that attribute.jOOX is namespace-unaware. The supplied attribute name will be compared against all attributes, matching the first one that has the given name.
- See Also:
JOOX.convert(String, Class)
-
attrs
java.util.List<java.lang.String> attrs(java.lang.String name)
Get an attribute from all elements in the set of matched elementsjOOX is namespace-unaware. The supplied attribute name will be compared against all attributes, matching the first one that has the given name.
-
attrs
<T> java.util.List<T> attrs(java.lang.String name, java.lang.Class<T> type)
Get a converted attribute from all elements in the set of matched elementsjOOX is namespace-unaware. The supplied attribute name will be compared against all attributes, matching the first one that has the given name.
- See Also:
JOOX.convert(String, Class)
-
attr
Match attr(java.lang.String name, java.lang.String value)
Set an attribute on all elements in the set of matched elements. Ifvalue
is null, then the attribute is removed. If the attribute already exists, then it is replaced.
-
attr
Match attr(java.lang.String name, Content value)
Set an attribute on all elements in the set of matched elements. Ifvalue
returns null, then the attribute is removed. If the attribute already exists, then it is replaced.The callback
Context
is populated like this:-
Context.match()
- the matched element being attributed -
Context.matchIndex()
- the index of the matched element being attributed
-
-
removeAttr
Match removeAttr(java.lang.String name)
Remove an attribute from all elements in the set of matched elements. This is the same as callingattr(name, null)
.
-
contents
java.util.List<java.lang.String> contents()
Get all XML content of the elements in the set of matched elements.
-
contents
java.util.List<java.lang.String> contents(int... indexes)
Get all XML content of the elements at given indexes in the set of matched elements.
-
content
java.lang.String content()
Get the XML content of the first element in the set of matched elements, ornull
if there are no matched elements.This is the same as calling
content(0)
-
content
java.lang.String content(int index)
Get the XML content at a given index in the current set of matched elements.
-
content
Match content(java.lang.String content)
Add some XML content to all elements in the set of matched elements (possibly replacing existing content). If the supplied content is invalid XML or plain text, then it will be added as text just as withtext(String)
-
content
Match content(java.lang.Object content)
Add some JAXB-marshallable XML content to all elements in the set of matched elements (possibly replacing existing content).- See Also:
JOOX.$(Object)
,JOOX.content(Object)
-
content
Match content(Content content)
Add some XML content to all elements in the set of matched elements (possibly replacing existing content). If the supplied content is invalid XML or plain text, then it will be added as text just as withtext(String)
The callback
Context
is populated like this:-
Context.match()
- the matched element being added to -
Context.matchIndex()
- the index of the matched element being added to
-
-
texts
java.util.List<java.lang.String> texts()
Get all text content of the elements in the set of matched elements.
-
texts
<T> java.util.List<T> texts(java.lang.Class<T> type)
Get all converted text content of the elements in the set of matched elements.- See Also:
JOOX.convert(String, Class)
-
texts
java.util.List<java.lang.String> texts(int... indexes)
Get all text content of the elements at given indexes in the set of matched elements.
-
text
java.lang.String text()
Get the text content of the first element in the set of matched elements, ornull
if there are no matched elements.This is the same as calling
text(0)
-
text
<T> T text(java.lang.Class<T> type)
Get the converted text content of the first element in the set of matched elements, ornull
if there are no matched elements.- See Also:
JOOX.convert(String, Class)
-
text
java.lang.String text(int index)
Get the text content at a given index in the current set of matched elements.
-
text
Match text(java.lang.String content)
Set some text content to all elements in the set of matched elements (possibly replacing existing content).
-
text
Match text(Content content)
Set some text content to all elements in the set of matched elements (possibly replacing existing content).The callback
Context
is populated like this:-
Context.match()
- the matched element being added to -
Context.matchIndex()
- the index of the matched element being added to
-
-
cdatas
java.util.List<java.lang.String> cdatas()
Get all CDATA content of the elements in the set of matched elements.This is the same as
texts()
.
-
cdatas
<T> java.util.List<T> cdatas(java.lang.Class<T> type)
Get all converted CDATA content of the elements in the set of matched elements.This is the same as
texts(Class)
.- See Also:
JOOX.convert(String, Class)
-
cdatas
java.util.List<java.lang.String> cdatas(int... indexes)
Get all CDATA content of the elements at given indexes in the set of matched elements.This is the same as
texts(int...)
.
-
cdata
java.lang.String cdata()
Get the CDATA content of the first element in the set of matched elements, ornull
if there are no matched elements.This is the same as calling
cdata(0)
ortext()
.
-
cdata
<T> T cdata(java.lang.Class<T> type)
Get the converted CDATA content of the first element in the set of matched elements, ornull
if there are no matched elements.This is the same as
text(Class)
.- See Also:
JOOX.convert(String, Class)
-
cdata
java.lang.String cdata(int index)
Get the CDATA content at a given index in the current set of matched elements.This is the same as
text(int)
.
-
cdata
Match cdata(java.lang.String content)
Set some CDATA content to all elements in the set of matched elements (possibly replacing existing content).Unlike
text(Content)
, this generates aNode.CDATA_SECTION_NODE
.
-
cdata
Match cdata(Content content)
Set some CDATA content to all elements in the set of matched elements (possibly replacing existing content).The callback
Context
is populated like this:Context.match()
- the matched element being added toContext.matchIndex()
- the index of the matched element being added to
Unlike
text(Content)
, this generates aNode.CDATA_SECTION_NODE
.
-
copy
Match copy()
Get a copy of theMatch
wrapper. This is not a deep-copy of wrappedElement
objects. Both this and the copy will reference the sameElement
's
-
xpaths
java.util.List<java.lang.String> xpaths()
Get a list of XPath expressions describing the elements in the current set of matched elements
-
xpaths
java.util.List<java.lang.String> xpaths(int... indexes)
Get a list of XPath expressions describing the elements at the given indexes in the current set of matched elements
-
xpath
java.lang.String xpath()
Get an XPath expression describing the first element in the current set of matched elementsThis is the same as calling
xpath(0)
-
xpath
java.lang.String xpath(int index)
Get an XPath expression describing the element at a given index in the current set of matched elements
-
tags
java.util.List<java.lang.String> tags()
Get a list of tag names of the elements in the current set of matched elements.
-
tags
java.util.List<java.lang.String> tags(int... indexes)
Get a list of tag names of the elements at given indexes in the current set of matched elements.
-
tag
java.lang.String tag()
Get the tag name of the first element in the current set of matched elements.This is the same as calling
tag(0)
-
tag
java.lang.String tag(int index)
Get a tag name of the element at a given index in the current set of matched elements.
-
ids
java.util.List<java.lang.String> ids()
Get a list of id values in the current set of matched elements.This is the same as calling
attrs("id")
-
ids
java.util.List<java.lang.String> ids(int... indexes)
Get a list of id values at given indexes in the current set of matched elements.
-
ids
<T> java.util.List<T> ids(java.lang.Class<T> type)
Get a list of converted id values in the current set of matched elements.- See Also:
JOOX.convert(String, Class)
-
id
java.lang.String id()
Get the first id valueThis is the same as calling
id(0)
-
id
java.lang.String id(int index)
Get an id value at a given index in the current set of matched elements.This is the same as calling
eq(index).attr("id")
-
id
<T> T id(java.lang.Class<T> type)
Get the first converted id value- See Also:
JOOX.convert(String, Class)
-
write
Match write(java.io.Writer writer) throws java.io.IOException
Write the set of matched elements into a writerIf the set contains more or less than
1
element, this will result in writing non-well-formed XML- Throws:
java.io.IOException
-
write
Match write(java.io.OutputStream stream) throws java.io.IOException
Write the set of matched elements into a streamIf the set contains more or less than
1
element, this will result in writing non-well-formed XML- Throws:
java.io.IOException
-
write
Match write(java.io.File file) throws java.io.IOException
Write the set of matched elements into a fileIf the set contains more or less than
1
element, this will result in writing non-well-formed XML- Throws:
java.io.IOException
-
unmarshal
<T> java.util.List<T> unmarshal(java.lang.Class<T> type)
Unmarshal the current set of matched elements into a JAXB-annotated type.
-
unmarshal
<T> java.util.List<T> unmarshal(java.lang.Class<T> type, int... indexes)
Unmarshal the current set of matched elements at given indexes into a JAXB-annotated type.
-
unmarshalOne
<T> T unmarshalOne(java.lang.Class<T> type)
Unmarshal the first element in the current set of matched elements into a JAXB-annotated type.This is the same as calling
unmarshalOne(type, 0)
-
unmarshalOne
<T> T unmarshalOne(java.lang.Class<T> type, int index)
Unmarshal the element at a given index in the current set of matched elements into a JAXB-annotated type.This is the same as calling
unmarshalOne(type, 0)
-
transform
Match transform(javax.xml.transform.Transformer transformer)
Transform all elements in the set of matched elements.This will apply a given
Transformer
to every element in the set of matched elements. Every element in the set of matched elements will be replaced by its correspondingResult
obtained from thetransformer
.Example Input:
<books> <book id="1"/> <book id="2"/> </books>
Example XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="book"> <book id=""> <xsl:apply-templates/> </book> </xsl:template> <xsl:template match="@*|*"> <xsl:copy> <xsl:apply-templates select="*|@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Apply transformation:
// Applies transformation to the document element: $(document).transform("increment.xsl"); // Applies transformation to every book element: $(document).find("book").transform("increment.xsl");
Result:
<books> <book id="2"/> <book id="3"/> </books>
-
transform
Match transform(javax.xml.transform.Source transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
transform
Match transform(java.io.InputStream transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
transform
Match transform(java.io.Reader transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
transform
Match transform(java.net.URL transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
transform
Match transform(java.io.File transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
transform
Match transform(java.lang.String transformer)
Transform all elements in the set of matched elements.- See Also:
transform(Transformer)
-
sort
Match sort(java.util.Comparator<org.w3c.dom.Element> comparator)
Allows to sort the result with the given comparator.- Parameters:
comparator
- The element comparator.- Returns:
-
-