|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler groovy.util.XmlSlurper
public class XmlSlurper extends org.xml.sax.helpers.DefaultHandler
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!'] }
Constructor Summary | |
XmlSlurper()
Uses the defaults of not validating and namespace aware. |
|
XmlSlurper(boolean validating, boolean namespaceAware)
|
|
XmlSlurper(org.xml.sax.XMLReader reader)
|
|
XmlSlurper(javax.xml.parsers.SAXParser parser)
|
Method Summary | |
---|---|
void
|
characters(char[] ch, int start, int length)
|
void
|
endDocument()
|
void
|
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
|
org.xml.sax.DTDHandler
|
getDTDHandler()
|
GPathResult
|
getDocument()
@return 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 |
org.xml.sax.EntityResolver
|
getEntityResolver()
|
org.xml.sax.ErrorHandler
|
getErrorHandler()
|
boolean
|
getFeature(java.lang.String uri)
|
java.lang.Object
|
getProperty(java.lang.String uri)
|
GPathResult
|
parse(org.xml.sax.InputSource input)
Parse the content of the specified input source into a GPathResult object |
GPathResult
|
parse(java.io.File file)
Parses the content of the given file as XML turning it into a GPathResult object |
GPathResult
|
parse(java.io.InputStream input)
Parse the content of the specified input stream into an GPathResult Object. |
GPathResult
|
parse(java.io.Reader in)
Parse the content of the specified reader into a GPathResult Object. |
GPathResult
|
parse(java.lang.String uri)
Parse the content of the specified URI into a GPathResult Object |
GPathResult
|
parseText(java.lang.String text)
A helper method to parse the given text as XML |
void
|
setDTDHandler(org.xml.sax.DTDHandler dtdHandler)
|
void
|
setEntityBaseUrl(java.net.URL base)
Resolves entities against using the supplied URL as the base for relative URLs |
void
|
setEntityResolver(org.xml.sax.EntityResolver entityResolver)
|
void
|
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
|
void
|
setFeature(java.lang.String uri, boolean value)
|
void
|
setKeepWhitespace(boolean keepWhitespace)
|
void
|
setProperty(java.lang.String uri, java.lang.Object value)
|
void
|
startDocument()
|
void
|
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, Attributes atts)
|
void
|
startPrefixMapping(java.lang.String tag, java.lang.String uri)
|
Methods inherited from class org.xml.sax.helpers.DefaultHandler | |
---|---|
org.xml.sax.helpers.DefaultHandler#processingInstruction(java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#ignorableWhitespace([C, int, int), org.xml.sax.helpers.DefaultHandler#endDocument(), org.xml.sax.helpers.DefaultHandler#startDocument(), org.xml.sax.helpers.DefaultHandler#characters([C, int, int), org.xml.sax.helpers.DefaultHandler#fatalError(org.xml.sax.SAXParseException), org.xml.sax.helpers.DefaultHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes), org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#endPrefixMapping(java.lang.String), org.xml.sax.helpers.DefaultHandler#resolveEntity(java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator), org.xml.sax.helpers.DefaultHandler#skippedEntity(java.lang.String), org.xml.sax.helpers.DefaultHandler#startPrefixMapping(java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String), org.xml.sax.helpers.DefaultHandler#error(org.xml.sax.SAXParseException), org.xml.sax.helpers.DefaultHandler#warning(org.xml.sax.SAXParseException), org.xml.sax.helpers.DefaultHandler#wait(long, int), org.xml.sax.helpers.DefaultHandler#wait(long), org.xml.sax.helpers.DefaultHandler#wait(), org.xml.sax.helpers.DefaultHandler#equals(java.lang.Object), org.xml.sax.helpers.DefaultHandler#toString(), org.xml.sax.helpers.DefaultHandler#hashCode(), org.xml.sax.helpers.DefaultHandler#getClass(), org.xml.sax.helpers.DefaultHandler#notify(), org.xml.sax.helpers.DefaultHandler#notifyAll() |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
public XmlSlurper()
public XmlSlurper(boolean validating, boolean namespaceAware)
public XmlSlurper(org.xml.sax.XMLReader reader)
public XmlSlurper(javax.xml.parsers.SAXParser parser)
Method Detail |
---|
public void characters(char[] ch, int start, int length)
public void endDocument()
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
public org.xml.sax.DTDHandler getDTDHandler()
public GPathResult getDocument()
public org.xml.sax.EntityResolver getEntityResolver()
public org.xml.sax.ErrorHandler getErrorHandler()
public boolean getFeature(java.lang.String uri)
public java.lang.Object getProperty(java.lang.String uri)
public GPathResult parse(org.xml.sax.InputSource input)
input
- the InputSource to parse
public GPathResult parse(java.io.File file)
file
- the File to parse
public GPathResult parse(java.io.InputStream input)
input
- the InputStream to parse
public GPathResult parse(java.io.Reader in)
in
- the Reader to parse
public GPathResult parse(java.lang.String uri)
uri
- a String containing the URI to parse
public GPathResult parseText(java.lang.String text)
text
- a String containing XML to parse
public void setDTDHandler(org.xml.sax.DTDHandler dtdHandler)
public void setEntityBaseUrl(java.net.URL base)
base
- The URL used to resolve relative URLs
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
public void setFeature(java.lang.String uri, boolean value)
public void setKeepWhitespace(boolean keepWhitespace)
keepWhitespace
- If true then whitespace before elements is kept.
The default is to discard the whitespace.
public void setProperty(java.lang.String uri, java.lang.Object value)
public void startDocument()
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, Attributes atts)
public void startPrefixMapping(java.lang.String tag, java.lang.String uri)
Groovy Documentation