Package groovy.util
Class XmlSlurper
java.lang.Object
org.xml.sax.helpers.DefaultHandler
groovy.util.XmlSlurper
- All Implemented Interfaces:
- org.xml.sax.ContentHandler,- org.xml.sax.DTDHandler,- org.xml.sax.EntityResolver,- org.xml.sax.ErrorHandler
@Deprecated
public class XmlSlurper
extends org.xml.sax.helpers.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 SummaryConstructors Constructor Description XmlSlurper()Deprecated.Creates a non-validating and namespace-awareXmlSlurperwhich does not allow DOCTYPE declarations in documents.XmlSlurper(boolean validating, boolean namespaceAware)Deprecated.Creates aXmlSlurperwhich does not allow DOCTYPE declarations in documents.XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)Deprecated.Creates aXmlSlurper.XmlSlurper(javax.xml.parsers.SAXParser parser)Deprecated.XmlSlurper(org.xml.sax.XMLReader reader)Deprecated.
- 
Method SummaryModifier and Type Method Description voidcharacters(char[] ch, int start, int length)Deprecated.voidendDocument()Deprecated.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Deprecated.GPathResultgetDocument()Deprecated.org.xml.sax.DTDHandlergetDTDHandler()Deprecated.org.xml.sax.EntityResolvergetEntityResolver()Deprecated.org.xml.sax.ErrorHandlergetErrorHandler()Deprecated.booleangetFeature(java.lang.String uri)Deprecated.java.lang.ObjectgetProperty(java.lang.String uri)Deprecated.voidignorableWhitespace(char[] buffer, int start, int len)Deprecated.booleanisKeepIgnorableWhitespace()Deprecated.GPathResultparse(java.io.File file)Deprecated.Parses the content of the given file as XML turning it into a GPathResult objectGPathResultparse(java.io.InputStream input)Deprecated.Parse the content of the specified input stream into an GPathResult Object.GPathResultparse(java.io.Reader in)Deprecated.Parse the content of the specified reader into a GPathResult Object.GPathResultparse(java.lang.String uri)Deprecated.Parse the content of the specified URI into a GPathResult ObjectGPathResultparse(org.xml.sax.InputSource input)Deprecated.Parse the content of the specified input source into a GPathResult objectGPathResultparseText(java.lang.String text)Deprecated.A helper method to parse the given text as XMLvoidsetDTDHandler(org.xml.sax.DTDHandler dtdHandler)Deprecated.voidsetEntityBaseUrl(java.net.URL base)Deprecated.Resolves entities against using the supplied URL as the base for relative URLsvoidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)Deprecated.voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)Deprecated.voidsetFeature(java.lang.String uri, boolean value)Deprecated.voidsetKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)Deprecated.voidsetKeepWhitespace(boolean keepWhitespace)Deprecated.use setKeepIgnorableWhitespacevoidsetProperty(java.lang.String uri, java.lang.Object value)Deprecated.voidstartDocument()Deprecated.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)Deprecated.voidstartPrefixMapping(java.lang.String tag, java.lang.String uri)Deprecated.Methods inherited from class org.xml.sax.helpers.DefaultHandlerendPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warningMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandlerdeclaration
- 
Constructor Details- 
XmlSlurperpublic XmlSlurper() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates a non-validating and namespace-awareXmlSlurperwhich does not allow DOCTYPE declarations in documents.- Throws:
- javax.xml.parsers.ParserConfigurationException- if no parser which satisfies the requested configuration can be created.
- org.xml.sax.SAXException- for SAX errors.
 
- 
XmlSlurperpublic XmlSlurper(boolean validating, boolean namespaceAware) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates aXmlSlurperwhich does not allow DOCTYPE declarations in documents.- Parameters:
- validating-- trueif the parser should validate documents as they are parsed; false otherwise.
- namespaceAware-- trueif the parser should provide support for XML namespaces;- falseotherwise.
- Throws:
- javax.xml.parsers.ParserConfigurationException- if no parser which satisfies the requested configuration can be created.
- org.xml.sax.SAXException- for SAX errors.
 
- 
XmlSlurperpublic XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates aXmlSlurper.- Parameters:
- validating-- trueif the parser should validate documents as they are parsed; false otherwise.
- namespaceAware-- trueif the parser should provide support for XML namespaces;- falseotherwise.
- allowDocTypeDeclaration-- trueif the parser should provide support for DOCTYPE declarations;- falseotherwise.
- Throws:
- javax.xml.parsers.ParserConfigurationException- if no parser which satisfies the requested configuration can be created.
- org.xml.sax.SAXException- for SAX errors.
 
- 
XmlSlurperpublic XmlSlurper(org.xml.sax.XMLReader reader)Deprecated.
- 
XmlSlurperpublic XmlSlurper(javax.xml.parsers.SAXParser parser) throws org.xml.sax.SAXExceptionDeprecated.- Throws:
- org.xml.sax.SAXException
 
 
- 
- 
Method Details- 
setKeepWhitespace@Deprecated public void setKeepWhitespace(boolean keepWhitespace)Deprecated.use setKeepIgnorableWhitespace- Parameters:
- keepWhitespace- If true then whitespace before elements is kept. The default is to discard the whitespace.
 
- 
setKeepIgnorableWhitespacepublic 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.
 
- 
isKeepIgnorableWhitespacepublic boolean isKeepIgnorableWhitespace()Deprecated.- Returns:
- true if ignorable whitespace is kept
 
- 
getDocumentDeprecated.- 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
 
- 
parsepublic GPathResult parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXExceptionDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
parseDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
parsepublic GPathResult parse(java.io.InputStream input) throws java.io.IOException, org.xml.sax.SAXExceptionDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
parseDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
parsepublic GPathResult parse(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXExceptionDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
parseTextpublic GPathResult parseText(java.lang.String text) throws java.io.IOException, org.xml.sax.SAXExceptionDeprecated.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:
- org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
- java.io.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
 
- 
getDTDHandlerpublic org.xml.sax.DTDHandler getDTDHandler()Deprecated.
- 
getEntityResolverpublic org.xml.sax.EntityResolver getEntityResolver()Deprecated.
- 
getErrorHandlerpublic org.xml.sax.ErrorHandler getErrorHandler()Deprecated.
- 
getFeaturepublic boolean getFeature(java.lang.String uri) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionDeprecated.- Throws:
- org.xml.sax.SAXNotRecognizedException
- org.xml.sax.SAXNotSupportedException
 
- 
getPropertypublic java.lang.Object getProperty(java.lang.String uri) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionDeprecated.- Throws:
- org.xml.sax.SAXNotRecognizedException
- org.xml.sax.SAXNotSupportedException
 
- 
setDTDHandlerpublic void setDTDHandler(org.xml.sax.DTDHandler dtdHandler)Deprecated.
- 
setEntityResolverpublic void setEntityResolver(org.xml.sax.EntityResolver entityResolver)Deprecated.
- 
setEntityBaseUrlpublic void setEntityBaseUrl(java.net.URL base)Deprecated.Resolves entities against using the supplied URL as the base for relative URLs- Parameters:
- base- The URL used to resolve relative URLs
 
- 
setErrorHandlerpublic void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)Deprecated.
- 
setFeaturepublic void setFeature(java.lang.String uri, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionDeprecated.- Throws:
- org.xml.sax.SAXNotRecognizedException
- org.xml.sax.SAXNotSupportedException
 
- 
setPropertypublic void setProperty(java.lang.String uri, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionDeprecated.- Throws:
- org.xml.sax.SAXNotRecognizedException
- org.xml.sax.SAXNotSupportedException
 
- 
startDocumentpublic void startDocument() throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- startDocumentin interface- org.xml.sax.ContentHandler
- Overrides:
- startDocumentin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
startPrefixMappingpublic void startPrefixMapping(java.lang.String tag, java.lang.String uri) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- startPrefixMappingin interface- org.xml.sax.ContentHandler
- Overrides:
- startPrefixMappingin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
startElementpublic void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- startElementin interface- org.xml.sax.ContentHandler
- Overrides:
- startElementin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
ignorableWhitespacepublic void ignorableWhitespace(char[] buffer, int start, int len) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- ignorableWhitespacein interface- org.xml.sax.ContentHandler
- Overrides:
- ignorableWhitespacein class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
characterspublic void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- charactersin interface- org.xml.sax.ContentHandler
- Overrides:
- charactersin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
endElementpublic void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- endElementin interface- org.xml.sax.ContentHandler
- Overrides:
- endElementin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
- 
endDocumentpublic void endDocument() throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- endDocumentin interface- org.xml.sax.ContentHandler
- Overrides:
- endDocumentin class- org.xml.sax.helpers.DefaultHandler
- Throws:
- org.xml.sax.SAXException
 
 
- 
XmlSlurper