|
Groovy 2.2.0 | |||||||
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 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()
Creates a non-validating and non-namespace-aware |
|
XmlSlurper(boolean validating, boolean namespaceAware)
Creates a |
|
XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)
Creates a |
|
XmlSlurper(XMLReader reader)
|
|
XmlSlurper(SAXParser parser)
|
Method Summary | |
---|---|
void
|
characters(char[] ch, int start, int length)
|
void
|
endDocument()
|
void
|
endElement(String namespaceURI, String localName, String qName)
|
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 |
EntityResolver
|
getEntityResolver()
|
ErrorHandler
|
getErrorHandler()
|
boolean
|
getFeature(String uri)
|
Object
|
getProperty(String uri)
|
GPathResult
|
parse(InputSource input)
Parse the content of the specified input source into a GPathResult object |
GPathResult
|
parse(File file)
Parses the content of the given file as XML turning it into a GPathResult object |
GPathResult
|
parse(InputStream input)
Parse the content of the specified input stream into an GPathResult Object. |
GPathResult
|
parse(Reader in)
Parse the content of the specified reader into a GPathResult Object. |
GPathResult
|
parse(String uri)
Parse the content of the specified URI into a GPathResult Object |
GPathResult
|
parseText(String text)
A helper method to parse the given text as XML |
void
|
setDTDHandler(DTDHandler dtdHandler)
|
void
|
setEntityBaseUrl(URL base)
Resolves entities against using the supplied URL as the base for relative URLs |
void
|
setEntityResolver(EntityResolver entityResolver)
|
void
|
setErrorHandler(ErrorHandler errorHandler)
|
void
|
setFeature(String uri, boolean value)
|
void
|
setKeepWhitespace(boolean keepWhitespace)
|
void
|
setProperty(String uri, Object value)
|
void
|
startDocument()
|
void
|
startElement(String namespaceURI, String localName, String qName, Attributes atts)
|
void
|
startPrefixMapping(String tag, String uri)
|
Methods inherited from class DefaultHandler | |
---|---|
processingInstruction, ignorableWhitespace, startDocument, endDocument, characters, startElement, endElement, endPrefixMapping, notationDecl, fatalError, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, error, warning, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Constructor Detail |
---|
public XmlSlurper()
XmlSlurper
which does not allow DOCTYPE declarations in documents.
public XmlSlurper(boolean validating, boolean namespaceAware)
XmlSlurper
which does not allow DOCTYPE declarations in documents.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.
public XmlSlurper(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)
XmlSlurper
.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.
public XmlSlurper(XMLReader reader)
public XmlSlurper(SAXParser parser)
Method Detail |
---|
public void characters(char[] ch, int start, int length)
public void endDocument()
public void endElement(String namespaceURI, String localName, String qName)
public DTDHandler getDTDHandler()
public GPathResult getDocument()
public EntityResolver getEntityResolver()
public ErrorHandler getErrorHandler()
public boolean getFeature(String uri)
public Object getProperty(String uri)
public GPathResult parse(InputSource input)
input
- the InputSource to parse
public GPathResult parse(File file)
file
- the File to parse
public GPathResult parse(InputStream input)
input
- the InputStream to parse
public GPathResult parse(Reader in)
in
- the Reader to parse
public GPathResult parse(String uri)
uri
- a String containing the URI to parse
public GPathResult parseText(String text)
text
- a String containing XML to parse
public void setDTDHandler(DTDHandler dtdHandler)
public void setEntityBaseUrl(URL base)
base
- The URL used to resolve relative URLs
public void setEntityResolver(EntityResolver entityResolver)
public void setErrorHandler(ErrorHandler errorHandler)
public void setFeature(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(String uri, Object value)
public void startDocument()
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
public void startPrefixMapping(String tag, String uri)
Copyright © 2003-2013 The Codehaus. All rights reserved.