Package groovy.util
Class XmlParser
java.lang.Object
groovy.util.XmlParser
- All Implemented Interfaces:
- org.xml.sax.ContentHandler
@Deprecated
public class XmlParser
extends java.lang.Object
implements org.xml.sax.ContentHandler
Deprecated.
A helper class for parsing XML into a tree of Node instances for a
 simple way of processing XML. This parser does not preserve the XML
 InfoSet - if that's what you need try using W3C DOM, dom4j, JDOM, XOM etc.
 This parser ignores comments and processing instructions and converts
 the XML into a Node for each element in the XML with attributes
 and child Nodes and Strings. This simple model is sufficient for
 most simple use cases of processing XML.
 
Example usage:
 def xml = '<root><one a1="uno!"/><two>Some text!</two></root>'
 def rootNode = new XmlParser().parseText(xml)
 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'] }
 - 
Constructor SummaryConstructors Constructor Description XmlParser()Deprecated.Creates a non-validating and namespace-awareXmlParserwhich does not allow DOCTYPE declarations in documents.XmlParser(boolean validating, boolean namespaceAware)Deprecated.Creates aXmlParserwhich does not allow DOCTYPE declarations in documents.XmlParser(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)Deprecated.Creates aXmlParser.XmlParser(javax.xml.parsers.SAXParser parser)Deprecated.XmlParser(org.xml.sax.XMLReader reader)Deprecated.
- 
Method SummaryModifier and Type Method Description protected voidaddTextToNode()Deprecated.voidcharacters(char[] buffer, int start, int length)Deprecated.protected NodecreateNode(Node parent, java.lang.Object name, java.util.Map attributes)Deprecated.Creates a new node with the given parent, name, and attributes.voidendDocument()Deprecated.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Deprecated.voidendPrefixMapping(java.lang.String prefix)Deprecated.org.xml.sax.LocatorgetDocumentLocator()Deprecated.org.xml.sax.DTDHandlergetDTDHandler()Deprecated.protected java.lang.ObjectgetElementName(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Deprecated.Return a name given the namespaceURI, localName and qName.org.xml.sax.EntityResolvergetEntityResolver()Deprecated.org.xml.sax.ErrorHandlergetErrorHandler()Deprecated.booleangetFeature(java.lang.String uri)Deprecated.java.lang.ObjectgetProperty(java.lang.String uri)Deprecated.protected org.xml.sax.XMLReadergetXMLReader()Deprecated.voidignorableWhitespace(char[] buffer, int start, int len)Deprecated.booleanisKeepIgnorableWhitespace()Deprecated.Returns the current keep ignorable whitespace setting.booleanisNamespaceAware()Deprecated.Determine if namespace handling is enabled.booleanisTrimWhitespace()Deprecated.Returns the current trim whitespace setting.Nodeparse(java.io.File file)Deprecated.Parses the content of the given file as XML turning it into a tree of Nodes.Nodeparse(java.io.InputStream input)Deprecated.Parse the content of the specified input stream into a tree of Nodes.Nodeparse(java.io.Reader in)Deprecated.Parse the content of the specified reader into a tree of Nodes.Nodeparse(java.lang.String uri)Deprecated.Parse the content of the specified URI into a tree of Nodes.Nodeparse(org.xml.sax.InputSource input)Deprecated.Parse the content of the specified input source into a tree of Nodes.NodeparseText(java.lang.String text)Deprecated.A helper method to parse the given text as XML.voidprocessingInstruction(java.lang.String target, java.lang.String data)Deprecated.voidsetDocumentLocator(org.xml.sax.Locator locator)Deprecated.voidsetDTDHandler(org.xml.sax.DTDHandler dtdHandler)Deprecated.voidsetEntityResolver(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.Sets the keep ignorable whitespace setting value.voidsetNamespaceAware(boolean namespaceAware)Deprecated.Enable and/or disable namespace handling.voidsetProperty(java.lang.String uri, java.lang.Object value)Deprecated.voidsetTrimWhitespace(boolean trimWhitespace)Deprecated.Sets the trim whitespace setting value.voidskippedEntity(java.lang.String name)Deprecated.voidstartDocument()Deprecated.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list)Deprecated.voidstartPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI)Deprecated.Methods 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- 
XmlParserpublic XmlParser() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates a non-validating and namespace-awareXmlParserwhich 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.
 
- 
XmlParserpublic XmlParser(boolean validating, boolean namespaceAware) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates aXmlParserwhich 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.
 
- 
XmlParserpublic XmlParser(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXExceptionDeprecated.Creates aXmlParser.- 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.
 
- 
XmlParserpublic XmlParser(org.xml.sax.XMLReader reader)Deprecated.
- 
XmlParserpublic XmlParser(javax.xml.parsers.SAXParser parser) throws org.xml.sax.SAXExceptionDeprecated.- Throws:
- org.xml.sax.SAXException
 
 
- 
- 
Method Details- 
isTrimWhitespacepublic boolean isTrimWhitespace()Deprecated.Returns the current trim whitespace setting.- Returns:
- true if whitespace will be trimmed
 
- 
setTrimWhitespacepublic void setTrimWhitespace(boolean trimWhitespace)Deprecated.Sets the trim whitespace setting value.- Parameters:
- trimWhitespace- the desired setting value
 
- 
isKeepIgnorableWhitespacepublic boolean isKeepIgnorableWhitespace()Deprecated.Returns the current keep ignorable whitespace setting.- Returns:
- true if ignorable whitespace will be kept (default false)
 
- 
setKeepIgnorableWhitespacepublic void setKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)Deprecated.Sets the keep ignorable whitespace setting value.- Parameters:
- keepIgnorableWhitespace- the desired new value
 
- 
parseDeprecated.Parses the content of the given file as XML turning it into a tree of Nodes.- Parameters:
- file- the File containing the XML to be parsed
- Returns:
- the root node of the parsed tree of Nodes
- 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 Node parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXExceptionDeprecated.Parse the content of the specified input source into a tree of Nodes.- Parameters:
- input- the InputSource for the XML to parse
- Returns:
- the root node of the parsed tree of Nodes
- 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 input stream into a tree of Nodes.Note that using this method will not provide the parser with any URI for which to find DTDs etc - Parameters:
- input- an InputStream containing the XML to be parsed
- Returns:
- the root node of the parsed tree of Nodes
- 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 tree of Nodes.Note that using this method will not provide the parser with any URI for which to find DTDs etc - Parameters:
- in- a Reader to read the XML to be parsed
- Returns:
- the root node of the parsed tree of Nodes
- 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 URI into a tree of Nodes.- Parameters:
- uri- a String containing a uri pointing to the XML to be parsed
- Returns:
- the root node of the parsed tree of Nodes
- 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.
 
- 
parseTextDeprecated.A helper method to parse the given text as XML.- Parameters:
- text- the XML text to parse
- Returns:
- the root node of the parsed tree of Nodes
- 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.
 
- 
isNamespaceAwarepublic boolean isNamespaceAware()Deprecated.Determine if namespace handling is enabled.- Returns:
- true if namespace handling is enabled
 
- 
setNamespaceAwarepublic void setNamespaceAware(boolean namespaceAware)Deprecated.Enable and/or disable namespace handling.- Parameters:
- namespaceAware- the new desired value
 
- 
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.
- 
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
- Throws:
- org.xml.sax.SAXException
 
- 
endDocumentpublic void endDocument() throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- endDocumentin interface- org.xml.sax.ContentHandler
- Throws:
- org.xml.sax.SAXException
 
- 
startElementpublic void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- startElementin interface- org.xml.sax.ContentHandler
- 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
- Throws:
- org.xml.sax.SAXException
 
- 
characterspublic void characters(char[] buffer, int start, int length) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- charactersin interface- org.xml.sax.ContentHandler
- Throws:
- org.xml.sax.SAXException
 
- 
startPrefixMappingpublic void startPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- startPrefixMappingin interface- org.xml.sax.ContentHandler
- Throws:
- org.xml.sax.SAXException
 
- 
endPrefixMappingpublic void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- endPrefixMappingin interface- org.xml.sax.ContentHandler
- 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
- Throws:
- org.xml.sax.SAXException
 
- 
processingInstructionpublic void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- processingInstructionin interface- org.xml.sax.ContentHandler
- Throws:
- org.xml.sax.SAXException
 
- 
getDocumentLocatorpublic org.xml.sax.Locator getDocumentLocator()Deprecated.
- 
setDocumentLocatorpublic void setDocumentLocator(org.xml.sax.Locator locator)Deprecated.- Specified by:
- setDocumentLocatorin interface- org.xml.sax.ContentHandler
 
- 
skippedEntitypublic void skippedEntity(java.lang.String name) throws org.xml.sax.SAXExceptionDeprecated.- Specified by:
- skippedEntityin interface- org.xml.sax.ContentHandler
- Throws:
- org.xml.sax.SAXException
 
- 
getXMLReaderprotected org.xml.sax.XMLReader getXMLReader()Deprecated.
- 
addTextToNodeprotected void addTextToNode()Deprecated.
- 
createNodeDeprecated.Creates a new node with the given parent, name, and attributes. The default implementation returns an instance ofgroovy.util.Node.- Parameters:
- parent- the parent node, or null if the node being created is the root node
- name- an Object representing the name of the node (typically an instance of- QName)
- attributes- a Map of attribute names to attribute values
- Returns:
- a new Node instance representing the current node
 
- 
getElementNameprotected java.lang.Object getElementName(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)Deprecated.Return a name given the namespaceURI, localName and qName.- Parameters:
- namespaceURI- the namespace URI
- localName- the local name
- qName- the qualified name
- Returns:
- the newly created representation of the name
 
 
- 
XmlParser