Package groovy.util
Class XmlParser
java.lang.Object
groovy.util.XmlParser
- All Implemented Interfaces:
ContentHandler
@Deprecated public class XmlParser extends Object implements ContentHandler
Deprecated.
use
XmlParserA 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 Summary
Constructors 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(SAXParser parser)Deprecated.XmlParser(XMLReader reader)Deprecated. -
Method Summary
Modifier and Type Method Description protected voidaddTextToNode()Deprecated.voidcharacters(char[] buffer, int start, int length)Deprecated.protected NodecreateNode(Node parent, Object name, Map attributes)Deprecated.Creates a new node with the given parent, name, and attributes.voidendDocument()Deprecated.voidendElement(String namespaceURI, String localName, String qName)Deprecated.voidendPrefixMapping(String prefix)Deprecated.LocatorgetDocumentLocator()Deprecated.DTDHandlergetDTDHandler()Deprecated.protected ObjectgetElementName(String namespaceURI, String localName, String qName)Deprecated.Return a name given the namespaceURI, localName and qName.EntityResolvergetEntityResolver()Deprecated.ErrorHandlergetErrorHandler()Deprecated.booleangetFeature(String uri)Deprecated.ObjectgetProperty(String uri)Deprecated.protected 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(File file)Deprecated.Parses the content of the given file as XML turning it into a tree of Nodes.Nodeparse(InputStream input)Deprecated.Parse the content of the specified input stream into a tree of Nodes.Nodeparse(Reader in)Deprecated.Parse the content of the specified reader into a tree of Nodes.Nodeparse(String uri)Deprecated.Parse the content of the specified URI into a tree of Nodes.Nodeparse(InputSource input)Deprecated.Parse the content of the specified input source into a tree of Nodes.NodeparseText(String text)Deprecated.A helper method to parse the given text as XML.voidprocessingInstruction(String target, String data)Deprecated.voidsetDocumentLocator(Locator locator)Deprecated.voidsetDTDHandler(DTDHandler dtdHandler)Deprecated.voidsetEntityResolver(EntityResolver entityResolver)Deprecated.voidsetErrorHandler(ErrorHandler errorHandler)Deprecated.voidsetFeature(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(String uri, Object value)Deprecated.voidsetTrimWhitespace(boolean trimWhitespace)Deprecated.Sets the trim whitespace setting value.voidskippedEntity(String name)Deprecated.voidstartDocument()Deprecated.voidstartElement(String namespaceURI, String localName, String qName, Attributes list)Deprecated.voidstartPrefixMapping(String prefix, String namespaceURI)Deprecated.
-
Constructor Details
-
XmlParser
Deprecated.Creates a non-validating and namespace-awareXmlParserwhich does not allow DOCTYPE declarations in documents.- Throws:
ParserConfigurationException- if no parser which satisfies the requested configuration can be created.SAXException- for SAX errors.
-
XmlParser
public XmlParser(boolean validating, boolean namespaceAware) throws ParserConfigurationException, 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:
ParserConfigurationException- if no parser which satisfies the requested configuration can be created.SAXException- for SAX errors.
-
XmlParser
public XmlParser(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws ParserConfigurationException, 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:
ParserConfigurationException- if no parser which satisfies the requested configuration can be created.SAXException- for SAX errors.
-
XmlParser
Deprecated. -
XmlParser
Deprecated.- Throws:
SAXException
-
-
Method Details
-
isTrimWhitespace
public boolean isTrimWhitespace()Deprecated.Returns the current trim whitespace setting.- Returns:
- true if whitespace will be trimmed
-
setTrimWhitespace
public void setTrimWhitespace(boolean trimWhitespace)Deprecated.Sets the trim whitespace setting value.- Parameters:
trimWhitespace- the desired setting value
-
isKeepIgnorableWhitespace
public boolean isKeepIgnorableWhitespace()Deprecated.Returns the current keep ignorable whitespace setting.- Returns:
- true if ignorable whitespace will be kept (default false)
-
setKeepIgnorableWhitespace
public void setKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)Deprecated.Sets the keep ignorable whitespace setting value.- Parameters:
keepIgnorableWhitespace- the desired new value
-
parse
Deprecated.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:
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 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:
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 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:
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 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:
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 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:
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- the XML text to parse- Returns:
- the root node of the parsed tree of Nodes
- 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.
-
isNamespaceAware
public boolean isNamespaceAware()Deprecated.Determine if namespace handling is enabled.- Returns:
- true if namespace handling is enabled
-
setNamespaceAware
public void setNamespaceAware(boolean namespaceAware)Deprecated.Enable and/or disable namespace handling.- Parameters:
namespaceAware- the new desired value
-
getDTDHandler
Deprecated. -
getEntityResolver
Deprecated. -
getErrorHandler
Deprecated. -
getFeature
Deprecated. -
getProperty
Deprecated. -
setDTDHandler
Deprecated. -
setEntityResolver
Deprecated. -
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:
startDocumentin interfaceContentHandler- Throws:
SAXException
-
endDocument
Deprecated.- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXExceptionDeprecated.- Specified by:
startElementin interfaceContentHandler- Throws:
SAXException
-
endElement
Deprecated.- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException
-
characters
Deprecated.- Specified by:
charactersin interfaceContentHandler- Throws:
SAXException
-
startPrefixMapping
Deprecated.- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
Deprecated.- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
ignorableWhitespace
Deprecated.- Specified by:
ignorableWhitespacein interfaceContentHandler- Throws:
SAXException
-
processingInstruction
Deprecated.- Specified by:
processingInstructionin interfaceContentHandler- Throws:
SAXException
-
getDocumentLocator
Deprecated. -
setDocumentLocator
Deprecated.- Specified by:
setDocumentLocatorin interfaceContentHandler
-
skippedEntity
Deprecated.- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
getXMLReader
Deprecated. -
addTextToNode
protected void addTextToNode()Deprecated. -
createNode
Deprecated.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 nodename- an Object representing the name of the node (typically an instance ofQName)attributes- a Map of attribute names to attribute values- Returns:
- a new Node instance representing the current node
-
getElementName
Deprecated.Return a name given the namespaceURI, localName and qName.- Parameters:
namespaceURI- the namespace URIlocalName- the local nameqName- the qualified name- Returns:
- the newly created representation of the name
-