Deprecated
def rootNode = new XmlSlurper().parseText(
'<root><one a1="uno!"/><two>Some text!</two></root>' )
assert rootNode.name() == 'root'
assert rootNode.one[0].@a1 == 'uno!'
assert rootNode.two.text() == 'Some text!'
rootNode.children().each { assert it.name() in ['one','two'] }
Note that in some cases, a 'selector' expression may not resolve to a single node. For example:
def rootNode = new XmlSlurper().parseText(
'''<root>
<a>one!</a>
<a>two!</a>
</root>''' )
assert rootNode.a.size() == 2
rootNode.a.each { assert it.text() in ['one!','two!'] }
GPathResult
| Modifier and Type | Field and Description |
|---|---|
| private final StringBuilder | |
| private Node | currentNode
Deprecated
as a consequence of
Node being deprecated.
|
| private boolean | |
| private boolean | |
| private final Map | |
| private final XMLReader | |
| private final Stack |
| Access | Constructor and Description |
|---|---|
| public | XmlSlurper()
Creates a non-validating and namespace-aware |
| public | XmlSlurper(final boolean
true if the parser should validate documents as they are parsed; false otherwise.true if the parser should provide support for XML namespaces; false otherwise.Creates a |
| public | XmlSlurper(final boolean
true if the parser should validate documents as they are parsed; false otherwise.true if the parser should provide support for XML namespaces; false otherwise.true if the parser should provide support for DOCTYPE declarations; false otherwise.Creates a |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | characters(final char[]
The characters. ch, final int The start position in the character array. start, final int The number of characters to use from the
character array. length)Overrides org. Implements org. |
| public void | endDocument()
Overrides org. Implements org. |
| public void | endElement(final String
The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed. namespaceURI, final String The local name (without prefix), or the
empty string if Namespace processing is not being
performed. localName, final String The qualified name (with prefix), or the
empty string if qualified names are not available. qName)Overrides org. Implements org. |
| public GPathResult | Returns: The GPathResult instance created by consuming a stream of SAX events Note if one of the parse methods has been called then this returns null Note if this is called more than once all calls after the first will return null
Deprecated
as a consequence of
GPathResult being deprecated.
|
| public DTDHandler | |
| public EntityResolver | |
| public ErrorHandler | |
| public boolean | |
| public Object | |
| public void | ignorableWhitespace(char[]
The whitespace characters. buffer, int The start position in the character array. start, int The number of characters to use from the
character array. len)Overrides org. Implements org. |
| public boolean | |
| public GPathResult | Returns: An object which supports GPath expressionsthe InputSource to parse input)
Deprecated
as a consequence of
Parse the content of the specified input source into a GPathResult object
GPathResult being deprecated.
|
| public GPathResult | Returns: An object which supports GPath expressionsthe File to parse file)
Deprecated
as a consequence of
Parses the content of the given file as XML turning it into a GPathResult object
GPathResult being deprecated.
|
| public GPathResult | Returns: An object which supports GPath expressionsthe InputStream to parse input)
Deprecated
as a consequence of
Parse the content of the specified input stream into an GPathResult Object.
GPathResult being deprecated.
|
| public GPathResult | Returns: An object which supports GPath expressionsthe Reader to parse in)
Deprecated
as a consequence of
Parse the content of the specified reader into a GPathResult Object.
GPathResult being deprecated.
|
| public GPathResult | Returns: An object which supports GPath expressionsa String containing the URI to parse uri)
Deprecated
as a consequence of
Parse the content of the specified URI into a GPathResult Object
GPathResult being deprecated.
|
| public GPathResult | Returns: An object which supports GPath expressionsa String containing XML to parse text)
Deprecated
as a consequence of
A helper method to parse the given text as XML
GPathResult being deprecated.
|
| public void | |
| public void | setEntityBaseUrl(final URL
The URL used to resolve relative URLs base)Resolves entities against using the supplied URL as the base for relative URLs |
| public void | |
| public void | |
| public void | |
| public void | setKeepIgnorableWhitespace(boolean
If true then ignorable whitespace (i.e. whitespace before elements) is kept.
The default is to discard the whitespace. keepIgnorableWhitespace)
|
| public void | setKeepWhitespace(boolean
If true then whitespace before elements is kept.
The default is to discard the whitespace. keepWhitespace)
Deprecated
use setKeepIgnorableWhitespace
|
| public void | |
| private static void | |
| public void | startDocument()
Overrides org. Implements org. |
| public void | startElement(final String
The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed. namespaceURI, final String The local name (without prefix), or the
empty string if Namespace processing is not being
performed. localName, final String The qualified name (with prefix), or the
empty string if qualified names are not available. qName, final Attributes The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object. atts)Overrides org. Implements org. |
| public void | startPrefixMapping(final String
The Namespace prefix being declared. tag, final String The Namespace URI mapped to the prefix. uri)Overrides org. Implements org. |
| charBuffer | back to summary |
|---|---|
| private final StringBuilder charBuffer | |
| currentNode | back to summary |
|---|---|
| private Node currentNode
Deprecated as a consequence of | |
| keepIgnorableWhitespace | back to summary |
|---|---|
| private boolean keepIgnorableWhitespace | |
| namespaceAware | back to summary |
|---|---|
| private boolean namespaceAware | |
| namespaceTagHints | back to summary |
|---|---|
| private final Map<String, String> namespaceTagHints | |
| reader | back to summary |
|---|---|
| private final XMLReader reader | |
| stack | back to summary |
|---|---|
| private final Stack<Node> stack | |
| XmlSlurper | back to summary |
|---|---|
| public XmlSlurper() throws ParserConfigurationException, SAXException Creates a non-validating and namespace-aware
| |
| XmlSlurper | back to summary |
|---|---|
| public XmlSlurper(final boolean validating, final boolean namespaceAware) throws ParserConfigurationException, SAXException Creates a
| |
| XmlSlurper | back to summary |
|---|---|
| public XmlSlurper(final boolean validating, final boolean namespaceAware, boolean allowDocTypeDeclaration) throws ParserConfigurationException, SAXException Creates a
| |
| XmlSlurper | back to summary |
|---|---|
| public XmlSlurper(final XMLReader reader) | |
| XmlSlurper | back to summary |
|---|---|
| public XmlSlurper(final SAXParser parser) throws SAXException | |
| addCdata | back to summary |
|---|---|
| private void addCdata() | |
| characters | back to summary |
|---|---|
| public void characters(final char[] ch, final int start, final int length) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of character data inside an element. By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).
| |
| endDocument | back to summary |
|---|---|
| public void endDocument() throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the end of the document. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of a document (such as finalising a tree or closing an output file).
| |
| endElement | back to summary |
|---|---|
| public void endElement(final String namespaceURI, final String localName, final String qName) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the end of an element. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).
| |
| getDocument | back to summary |
|---|---|
| public GPathResult getDocument()
Deprecated as a consequence of
| |
| getDTDHandler | back to summary |
|---|---|
| public DTDHandler getDTDHandler() | |
| getEntityResolver | back to summary |
|---|---|
| public EntityResolver getEntityResolver() | |
| getErrorHandler | back to summary |
|---|---|
| public ErrorHandler getErrorHandler() | |
| getFeature | back to summary |
|---|---|
| public boolean getFeature(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException | |
| getProperty | back to summary |
|---|---|
| public Object getProperty(final String uri) throws SAXNotRecognizedException, SAXNotSupportedException | |
| ignorableWhitespace | back to summary |
|---|---|
| public void ignorableWhitespace(char[] buffer, int start, int len) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of ignorable whitespace in element content. By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).
| |
| isKeepIgnorableWhitespace | back to summary |
|---|---|
public boolean isKeepIgnorableWhitespace()
| |
| parse | back to summary |
|---|---|
| public GPathResult parse(final InputSource input) throws IOException, SAXException
Deprecated as a consequence of Parse the content of the specified input source into a GPathResult object
| |
| parse | back to summary |
|---|---|
| public GPathResult parse(final File file) throws IOException, SAXException
Deprecated as a consequence of Parses the content of the given file as XML turning it into a GPathResult object
| |
| parse | back to summary |
|---|---|
| public GPathResult parse(final InputStream input) throws IOException, SAXException
Deprecated as a consequence of Parse the content of the specified input stream into an GPathResult Object. Note that using this method will not provide the parser with any URI for which to find DTDs etc. It is up to you to close the InputStream after parsing is complete (if required).
| |
| parse | back to summary |
|---|---|
| public GPathResult parse(final Reader in) throws IOException, SAXException
Deprecated as a consequence of Parse the content of the specified reader into a GPathResult Object. Note that using this method will not provide the parser with any URI for which to find DTDs etc. It is up to you to close the Reader after parsing is complete (if required).
| |
| parse | back to summary |
|---|---|
| public GPathResult parse(final String uri) throws IOException, SAXException
Deprecated as a consequence of Parse the content of the specified URI into a GPathResult Object
| |
| parseText | back to summary |
|---|---|
| public GPathResult parseText(final String text) throws IOException, SAXException
Deprecated as a consequence of A helper method to parse the given text as XML
| |
| setDTDHandler | back to summary |
|---|---|
| public void setDTDHandler(final DTDHandler dtdHandler) | |
| setEntityBaseUrl | back to summary |
|---|---|
| public void setEntityBaseUrl(final URL base) Resolves entities against using the supplied URL as the base for relative URLs
| |
| setEntityResolver | back to summary |
|---|---|
| public void setEntityResolver(final EntityResolver entityResolver) | |
| setErrorHandler | back to summary |
|---|---|
| public void setErrorHandler(final ErrorHandler errorHandler) | |
| setFeature | back to summary |
|---|---|
| public void setFeature(final String uri, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException | |
| setKeepIgnorableWhitespace | back to summary |
|---|---|
public void setKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)
| |
| setKeepWhitespace | back to summary |
|---|---|
| public void setKeepWhitespace(boolean keepWhitespace)
Deprecated use setKeepIgnorableWhitespace
| |
| setProperty | back to summary |
|---|---|
| public void setProperty(final String uri, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException | |
| setQuietly | back to summary |
|---|---|
| private static void setQuietly(SAXParserFactory factory, String feature, boolean value) | |
| startDocument | back to summary |
|---|---|
| public void startDocument() throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the beginning of the document. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the beginning of a document (such as allocating the root node of a tree or creating an output file).
| |
| startElement | back to summary |
|---|---|
| public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the start of an element. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).
| |
| startPrefixMapping | back to summary |
|---|---|
| public void startPrefixMapping(final String tag, final String uri) throws SAXException Overrides org. Implements org. Doc from org. Receive notification of the start of a Namespace mapping. By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).
| |