public final class JOOX
extends java.lang.Object
Constructor | Description |
---|---|
JOOX() |
Modifier and Type | Method | Description |
---|---|---|
static Match |
$() |
Wrap a new empty document
|
static Match |
$(java.io.File file) |
Read a DOM document from a file into a
Match element set |
static Match |
$(java.io.InputStream stream) |
Read a DOM document from a stream into a
Match element set |
static Match |
$(java.io.Reader reader) |
Read a DOM document from a reader into a
Match element set |
static Match |
$(java.lang.Object object) |
Wrap a JAXB-marshallable element in a jOOX
Match element set |
static Match |
$(java.lang.String name) |
Create a new DOM element in an independent document
|
static Match |
$(java.lang.String name,
java.lang.String content) |
Create a new DOM element in an independent document
|
static Match |
$(java.lang.String name,
Match... content) |
Create a new DOM element in an independent document
|
static Match |
$(java.lang.String name,
org.w3c.dom.Element... content) |
Create a new DOM element in an independent document
|
static Match |
$(java.net.URI uri) |
Convenience method for calling
$(new File(uri)) |
static Match |
$(java.net.URL url) |
Convenience method for calling
$(url.openStream()) |
static Match |
$(Context context) |
Convenience method for calling
$(context.element()) |
static Match |
$(Match match) |
Convenience method for calling
$(match) |
static Match |
$(org.w3c.dom.Document document) |
Wrap a DOM document in a jOOX
Match element set |
static Match |
$(org.w3c.dom.Element element) |
Wrap a DOM element in a jOOX
Match element set |
static Match |
$(org.w3c.dom.Node node) |
Wrap a DOM
Node in a jOOX Match element set |
static Match |
$(org.w3c.dom.NodeList list) |
Wrap a DOM
NodeList in a jOOX Match element set |
static Match |
$(org.xml.sax.InputSource source) |
Read a DOM document from a file into a
Match element set |
static FastFilter |
all() |
A filter that always returns true
|
static Filter |
and(Filter... filters) |
Combine filters
|
static FastFilter |
at(int... indexes) |
A filter that returns true on elements at given iteration indexes
|
static FastFilter |
attr(java.lang.String name) |
A filter that returns all elements with a given attribute
|
static FastFilter |
attr(java.lang.String name,
java.lang.String... values) |
A filter that returns all elements with a given attribute being set to a
given value
|
static Mapper<java.lang.String> |
attrs(java.lang.String attributeName) |
Create a mapper that returns all attributes with a given name
|
static javax.xml.parsers.DocumentBuilder |
builder() |
Get a namespace-aware document builder
|
static Each |
chain(java.lang.Iterable<? extends Each> each) |
Chain several instances of
Each into a single one. |
static Each |
chain(Each... each) |
Chain several instances of
Each into a single one. |
static Content |
content(java.lang.Object value) |
Get a constant content that returns a marshalled, JAXB-annotated
value for all elements. |
static Content |
content(java.lang.String value) |
Get a constant content that returns the same
value for all
elements. |
static <T> T |
convert(java.lang.String value,
java.lang.Class<T> type) |
Convert a string value to any of these types:
String : The conversion has no effect
Byte : Numeric conversion. |
static <T> java.util.List<T> |
convert(java.util.List<java.lang.String> values,
java.lang.Class<T> type) |
Convert several values
|
static FastFilter |
even() |
A filter that returns true on all even iteration indexes (starting with
0!)
|
static Mapper<java.lang.String> |
ids() |
Create a mapper that returns all
id attributes |
static FastFilter |
ids(java.lang.String... ids) |
Create a filter matching id attributes
|
static java.lang.Iterable<org.w3c.dom.Element> |
iterable(org.w3c.dom.NodeList elements) |
Wrap a
NodeList into an Iterable |
static java.util.Iterator<org.w3c.dom.Element> |
iterator(org.w3c.dom.NodeList elements) |
Wrap a
NodeList into an Iterator |
static FastFilter |
leaf() |
A filter that returns true on leaf elements
|
static java.util.List<org.w3c.dom.Element> |
list(org.w3c.dom.NodeList elements) |
Wrap a
NodeList into an List |
static FastFilter |
matchAttr(java.lang.String name,
java.lang.String valueRegex) |
A filter that returns all elements whose text content matches a given
regex
|
static FastFilter |
matchTag(java.lang.String regex) |
A filter that returns all elements whose tag name matches a given regex
|
static FastFilter |
matchTag(java.lang.String regex,
boolean ignoreNamespace) |
A filter that returns all elements whose tag name matches a given regex
|
static FastFilter |
matchText(java.lang.String regex) |
A filter that returns all elements whose text content matches a given
regex
|
static FastFilter |
namespacePrefix(java.lang.String namespacePrefix) |
A filter that returns all elements with a given namespace prefix
|
static FastFilter |
namespaceURI(java.lang.String namespaceURI) |
A filter that returns all elements with a given namespace URI
|
static FastFilter |
none() |
A filter that always returns false
|
static Filter |
not(Filter filter) |
Inverse a filter
|
static FastFilter |
odd() |
A filter that returns true on all odd iteration indexes (starting with
0!)
|
static Filter |
or(Filter... filters) |
Combine filters
|
static Mapper<java.lang.String> |
paths() |
Create a mapper that returns all paths to given elements
|
static Filter |
selector(java.lang.String selector) |
A filter that returns all elements matched by a given selector.
|
static FastFilter |
tag(java.lang.String tagName) |
A filter that returns all elements with a given tag name
|
static FastFilter |
tag(java.lang.String tagName,
boolean ignoreNamespace) |
A filter that returns all elements with a given tag name
|
public static Match $()
public static Match $(java.lang.Object object)
Match
element setcontent(Object)
,
Match.content(Object)
public static Match $(java.lang.String name)
public static Match $(java.lang.String name, java.lang.String content)
public static Match $(java.lang.String name, org.w3c.dom.Element... content)
The added content is cloned into the new document
public static Match $(java.lang.String name, Match... content)
The added content is cloned into the new document
public static Match $(org.w3c.dom.Document document)
Match
element setpublic static Match $(org.w3c.dom.Element element)
Match
element setpublic static Match $(org.w3c.dom.Node node)
Node
in a jOOX Match
element set
Supported node types are
Document
: see $(Document)
Element
: see $(Element)
public static Match $(org.w3c.dom.NodeList list)
NodeList
in a jOOX Match
element set
If the supplied NodeList is empty or null, then an empty Match is created
public static Match $(java.net.URL url) throws org.xml.sax.SAXException, java.io.IOException
$(url.openStream())
org.xml.sax.SAXException
java.io.IOException
public static Match $(java.net.URI uri) throws org.xml.sax.SAXException, java.io.IOException
$(new File(uri))
org.xml.sax.SAXException
java.io.IOException
public static Match $(java.io.File file) throws org.xml.sax.SAXException, java.io.IOException
Match
element setjava.io.IOException
org.xml.sax.SAXException
public static Match $(java.io.InputStream stream) throws org.xml.sax.SAXException, java.io.IOException
Match
element setjava.io.IOException
org.xml.sax.SAXException
public static Match $(java.io.Reader reader) throws org.xml.sax.SAXException, java.io.IOException
Match
element setjava.io.IOException
org.xml.sax.SAXException
public static Match $(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, java.io.IOException
Match
element setjava.io.IOException
org.xml.sax.SAXException
public static FastFilter none()
public static FastFilter all()
public static FastFilter even()
public static FastFilter odd()
public static FastFilter leaf()
public static FastFilter at(int... indexes)
public static Filter selector(java.lang.String selector)
In most cases, this is the same as calling tag(String)
. In
Match.find(String)
, the following CSS-style selector syntax
elements are also supported:
Selector pattern | meaning |
---|---|
* | any element |
E | an element of type E |
E[foo] | an E element with a "foo" attribute |
E[foo="bar"] | an E element whose "foo" attribute value is exactly equal to "bar" |
E[foo~="bar"] | an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" |
E[foo^="bar"] | an E element whose "foo" attribute value begins exactly with the string "bar" |
E[foo$="bar"] | an E element whose "foo" attribute value ends exactly with the string "bar" |
E[foo*="bar"] | an E element whose "foo" attribute value contains the substring "bar" |
E[foo|="en"] | an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en" |
E:root | an E element, root of the document |
E:first-child | an E element, first child of its parent |
E:last-child | an E element, last child of its parent |
E:only-child | an E element, only child of its parent |
E:empty | an E element that has no children (including text nodes) |
E#myid | an E element with ID equal to "myid". |
E F | an F element descendant of an E element |
E > F | an F element child of an E element |
E + F | an F element immediately preceded by an E element |
E ~ F | an F element preceded by an E element |
Note that due to the presence of pseudo selectors, such as
:root
, :empty
, etc, namespaces are not
supported in selectors. Use jOOX's XPath functionality provided in
Match.xpath(String)
along with
Match.namespaces(java.util.Map)
if your XML document contains
namespaces
public static FastFilter tag(java.lang.String tagName)
This is the same as calling tag(tagName, true)
tag(String, boolean)
public static FastFilter tag(java.lang.String tagName, boolean ignoreNamespace)
This method allows for specifying whether namespace prefixes should be
ignored. This is particularly useful in DOM Level 1 documents, which are
namespace-unaware. In those methods
Document.getElementsByTagNameNS(String, String)
will not work, as
elements do not contain any localName
.
tagName
- The tag name to match. Use * as a special
tag name to match all tag namesignoreNamespace
- Whether namespace prefixes can be ignored. When
set to true
, then the namespace prefix is
ignored. When set to false
, then
tagName
must include the actual namespace prefix.public static FastFilter namespacePrefix(java.lang.String namespacePrefix)
null
and the empty string are treated equally to indicate
that no namespace prefix should be present.
public static FastFilter namespaceURI(java.lang.String namespaceURI)
null
and the empty string are treated equally to indicate
that no namespace URI should be present.
This only works if the underlying document is namespace-aware
public static FastFilter matchText(java.lang.String regex)
Pattern.matches(String, CharSequence)
public static FastFilter matchAttr(java.lang.String name, java.lang.String valueRegex)
Pattern.matches(String, CharSequence)
public static FastFilter matchTag(java.lang.String regex)
This is the same as calling matchTag(regex, true)
Pattern.matches(String, CharSequence)
public static FastFilter matchTag(java.lang.String regex, boolean ignoreNamespace)
This method allows for specifying whether namespace prefixes should be
ignored. This is particularly useful in DOM Level 1 documents, which are
namespace-unaware. In those methods
Document.getElementsByTagNameNS(String, String)
will not work, as
elements do not contain any localName
.
regex
- The regular expression to use for matching tag names.ignoreNamespace
- Whether namespace prefixes can be ignored. When
set to true
, then the namespace prefix is
ignored. When set to false
, then
regex
must also match potential namespace
prefixes.Pattern.matches(String, CharSequence)
public static FastFilter attr(java.lang.String name)
public static FastFilter attr(java.lang.String name, java.lang.String... values)
public static FastFilter ids(java.lang.String... ids)
public static Content content(java.lang.String value)
value
for all
elements.public static Content content(java.lang.Object value)
value
for all elements.$(Object)
,
Match.content(Object)
public static Mapper<java.lang.String> ids()
id
attributespublic static Mapper<java.lang.String> attrs(java.lang.String attributeName)
public static Mapper<java.lang.String> paths()
public static Each chain(Each... each)
Each
into a single one.
The resulting chained Each
produces a new Each
that can be used in the Match.each(Each)
method. I.e. every node
in a set of matched nodes will be passed to every chained
Each
, sequentially.
public static Each chain(java.lang.Iterable<? extends Each> each)
Each
into a single one.
The resulting chained Each
produces a new Each
that can be used in the Match.each(Each)
method. I.e. every node
in a set of matched nodes will be passed to every chained
Each
, sequentially.
public static java.lang.Iterable<org.w3c.dom.Element> iterable(org.w3c.dom.NodeList elements)
NodeList
into an Iterable
public static java.util.Iterator<org.w3c.dom.Element> iterator(org.w3c.dom.NodeList elements)
NodeList
into an Iterator
public static java.util.List<org.w3c.dom.Element> list(org.w3c.dom.NodeList elements)
NodeList
into an List
public static javax.xml.parsers.DocumentBuilder builder()
public static <T> T convert(java.lang.String value, java.lang.Class<T> type)
String
: The conversion has no effectByte
: Numeric conversion. NaN will return nullShort
: Numeric conversion. NaN will return nullInteger
: Numeric conversion. NaN will return nullLong
: Numeric conversion. NaN will return nullFloat
: Numeric conversion. NaN will return nullDouble
: Numeric conversion. NaN will return nullBigDecimal
: Numeric conversion. NaN will return nullBigInteger
: Numeric conversion. NaN will return nullBoolean
: Boolean conversion. Boolean values for
true
are any of these case-insensitive strings:
1
y
yes
true
on
enabled
false
are any of these case-insensitive
strings:
0
n
no
false
off
disabled
null
and illegal values will result in 0
or
false
Date
: Datetime conversion.Calendar
: Datetime conversion.GregorianCalendar
: Datetime conversion.Timestamp
: Datetime conversion. Possible patterns
for datetime conversion are
yyyy
: Only the year is parsedyyyy[-/]MM
: Year and month are parsed. Separator
characters are optionalyyyy[-/]MM[-/]dd
: Date is parsed. Separator characters
are optionaldd[-/.]MM[-/.]yyyy
: Date is parsed. Separator characters
are mandatoryyyyy[-/]MM[-/]dd[T ]HH
: Date and hour are parsed.
Separator characters are optionalyyyy[-/]MM[-/]dd[T ]HH[:]mm
: Date and time are parsed.
Separator characters are optionalyyyy[-/]MM[-/]dd[T ]HH[:]mm[:]ss
: Date and time are
parsed. Separator characters are optionalyyyy[-/]MM[-/]dd[T ]HH[:]mm[:]ss.SSS
: Date and time are
parsed. Separator characters are optionalDate
: Date conversion. Possible patterns for date
conversion are
yyyy
: Only the year is parsedyyyy[-/]MM
: Year and month are parsed. Separator
characters are optionalyyyy[-/]MM[-/]dd
: Date is parsed. Separator characters
are optionaldd[-/.]MM[-/.]yyyy
: Date is parsed. Separator characters
are mandatoryTime
: Time conversion. Possible patterns for time
conversion are
HH
: Hour is parsed. Separator characters are optionalHH[:]mm
: Hour and minute are parsed. Separator
characters are optionalHH[:]mm[:]ss
: Time is parsed. Separator characters are
optional
All other values evaluate to null
public static <T> java.util.List<T> convert(java.util.List<java.lang.String> values, java.lang.Class<T> type)
convert(String, Class)
Copyright © 2018. All rights reserved.