Package groovy.util
Class XmlSlurper
java.lang.Object
org.xml.sax.helpers.DefaultHandler
groovy.util.XmlSlurper
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
@Deprecated public class XmlSlurper extends DefaultHandler
Deprecated.
Parse XML into a document tree that may be traversed similar to XPath
expressions. For example:
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!'] }
- See Also:
GPathResult
-
Constructor Summary
Constructors Constructor Description XmlSlurper()
Deprecated.Creates a non-validating and namespace-awareXmlSlurper
which does not allow DOCTYPE declarations in documents.XmlSlurper(boolean validating, boolean namespaceAware)
Deprecated.Creates aXmlSlurper
which does not allow DOCTYPE declarations in documents.XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)
Deprecated.Creates aXmlSlurper
.XmlSlurper(SAXParser parser)
Deprecated.XmlSlurper(XMLReader reader)
Deprecated. -
Method Summary
Modifier and Type Method Description void
characters(char[] ch, int start, int length)
Deprecated.void
endDocument()
Deprecated.void
endElement(String namespaceURI, String localName, String qName)
Deprecated.GPathResult
getDocument()
Deprecated.DTDHandler
getDTDHandler()
Deprecated.EntityResolver
getEntityResolver()
Deprecated.ErrorHandler
getErrorHandler()
Deprecated.boolean
getFeature(String uri)
Deprecated.Object
getProperty(String uri)
Deprecated.void
ignorableWhitespace(char[] buffer, int start, int len)
Deprecated.boolean
isKeepIgnorableWhitespace()
Deprecated.GPathResult
parse(File file)
Deprecated.Parses the content of the given file as XML turning it into a GPathResult objectGPathResult
parse(InputStream input)
Deprecated.Parse the content of the specified input stream into an GPathResult Object.GPathResult
parse(Reader in)
Deprecated.Parse the content of the specified reader into a GPathResult Object.GPathResult
parse(String uri)
Deprecated.Parse the content of the specified URI into a GPathResult ObjectGPathResult
parse(InputSource input)
Deprecated.Parse the content of the specified input source into a GPathResult objectGPathResult
parseText(String text)
Deprecated.A helper method to parse the given text as XMLvoid
setDTDHandler(DTDHandler dtdHandler)
Deprecated.void
setEntityBaseUrl(URL base)
Deprecated.Resolves entities against using the supplied URL as the base for relative URLsvoid
setEntityResolver(EntityResolver entityResolver)
Deprecated.void
setErrorHandler(ErrorHandler errorHandler)
Deprecated.void
setFeature(String uri, boolean value)
Deprecated.void
setKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)
Deprecated.void
setKeepWhitespace(boolean keepWhitespace)
Deprecated.use setKeepIgnorableWhitespacevoid
setProperty(String uri, Object value)
Deprecated.void
startDocument()
Deprecated.void
startElement(String namespaceURI, String localName, String qName, Attributes atts)
Deprecated.void
startPrefixMapping(String tag, String uri)
Deprecated.Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
XmlSlurper
Deprecated.Creates a non-validating and namespace-awareXmlSlurper
which does not allow DOCTYPE declarations in documents.- Throws:
ParserConfigurationException
- if no parser which satisfies the requested configuration can be created.SAXException
- for SAX errors.
-
XmlSlurper
public XmlSlurper(boolean validating, boolean namespaceAware) throws ParserConfigurationException, SAXExceptionDeprecated.Creates aXmlSlurper
which does not allow DOCTYPE declarations in documents.- Parameters:
validating
-true
if the parser should validate documents as they are parsed; false otherwise.namespaceAware
-true
if the parser should provide support for XML namespaces;false
otherwise.- Throws:
ParserConfigurationException
- if no parser which satisfies the requested configuration can be created.SAXException
- for SAX errors.
-
XmlSlurper
public XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws ParserConfigurationException, SAXExceptionDeprecated.Creates aXmlSlurper
.- Parameters:
validating
-true
if the parser should validate documents as they are parsed; false otherwise.namespaceAware
-true
if the parser should provide support for XML namespaces;false
otherwise.allowDocTypeDeclaration
-true
if the parser should provide support for DOCTYPE declarations;false
otherwise.- Throws:
ParserConfigurationException
- if no parser which satisfies the requested configuration can be created.SAXException
- for SAX errors.
-
XmlSlurper
Deprecated. -
XmlSlurper
Deprecated.- Throws:
SAXException
-
-
Method Details
-
setKeepWhitespace
Deprecated.use setKeepIgnorableWhitespace- Parameters:
keepWhitespace
- If true then whitespace before elements is kept. The default is to discard the whitespace.
-
setKeepIgnorableWhitespace
public void setKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)Deprecated.- Parameters:
keepIgnorableWhitespace
- If true then ignorable whitespace (i.e. whitespace before elements) is kept. The default is to discard the whitespace.
-
isKeepIgnorableWhitespace
public boolean isKeepIgnorableWhitespace()Deprecated.- Returns:
- true if ignorable whitespace is kept
-
getDocument
Deprecated.- 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
-
parse
Deprecated.Parse the content of the specified input source into a GPathResult object- Parameters:
input
- the InputSource to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parse
Deprecated.Parses the content of the given file as XML turning it into a GPathResult object- Parameters:
file
- the File to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parse
Deprecated.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).- Parameters:
input
- the InputStream to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parse
Deprecated.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).- Parameters:
in
- the Reader to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parse
Deprecated.Parse the content of the specified URI into a GPathResult Object- Parameters:
uri
- a String containing the URI to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parseText
Deprecated.A helper method to parse the given text as XML- Parameters:
text
- a String containing XML to parse- Returns:
- An object which supports GPath expressions
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
getDTDHandler
Deprecated. -
getEntityResolver
Deprecated. -
getErrorHandler
Deprecated. -
getFeature
Deprecated. -
getProperty
Deprecated. -
setDTDHandler
Deprecated. -
setEntityResolver
Deprecated. -
setEntityBaseUrl
Deprecated.Resolves entities against using the supplied URL as the base for relative URLs- Parameters:
base
- The URL used to resolve relative URLs
-
setErrorHandler
Deprecated. -
setFeature
public void setFeature(String uri, boolean value) throws SAXNotRecognizedException, SAXNotSupportedExceptionDeprecated. -
setProperty
public void setProperty(String uri, Object value) throws SAXNotRecognizedException, SAXNotSupportedExceptionDeprecated. -
startDocument
Deprecated.- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
-
startPrefixMapping
Deprecated.- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classDefaultHandler
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXExceptionDeprecated.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
ignorableWhitespace
Deprecated.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Throws:
SAXException
-
characters
Deprecated.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
endElement
Deprecated.- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
endDocument
Deprecated.- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
-
XmlSlurper