Overview | Package | Class
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.util
Class XmlParser

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.

author:
  James Strachan

author:
  Paul King

version:
  $Revision: 10259 $

Field Summary
`StringBuffer` | `bodyText`
`Locator` | `locator`
`boolean` | `namespaceAware`
`Node` | `parent`
`XMLReader` | `reader`
`List` | `stack`
`boolean` | `trimWhitespace`

Constructor Summary
`XmlParser()`
`XmlParser(boolean validating, boolean namespaceAware)`
`XmlParser(XMLReader reader)`
`XmlParser(SAXParser parser)`

Method Summary
`void` | `addTextToNode()`
`void` | `characters(def buffer, int start, int length)`
`void` | `endDocument()`
`void` | `endElement(String namespaceURI, String localName, String qName)`
`void` | `endPrefixMapping(String prefix)`
`DTDHandler` | `getDTDHandler()`
`Locator` | `getDocumentLocator()`
`Object` | `getElementName(String namespaceURI, String localName, String qName)`
`EntityResolver` | `getEntityResolver()`
`ErrorHandler` | `getErrorHandler()`
`boolean` | `getFeature(String uri)`
`Object` | `getProperty(String uri)`
`XMLReader` | `getXMLReader()`
`void` | `ignorableWhitespace(def buffer, int start, int len)`
`boolean` | `isNamespaceAware()` Determine if namspace handling is enabled.
`boolean` | `isTrimWhitespace()` Returns the current trim whitespace setting.
`Node` | `parse(File file)` Parses the content of the given file as XML turning it into a tree of Nodes.
`Node` | `parse(InputSource input)` Parse the content of the specified input source into a tree of Nodes.
`Node` | `parse(InputStream input)` Parse the content of the specified input stream into a tree of Nodes.
`Node` | `parse(Reader in)` Parse the content of the specified reader into a tree of Nodes.
`Node` | `parse(String uri)` Parse the content of the specified URI into a tree of Nodes.
`Node` | `parseText(String text)` A helper method to parse the given text as XML.
`void` | `processingInstruction(String target, String data)`
`void` | `setDTDHandler(DTDHandler dtdHandler)`
`void` | `setDocumentLocator(Locator locator)`
`void` | `setEntityResolver(EntityResolver entityResolver)`
`void` | `setErrorHandler(ErrorHandler errorHandler)`
`void` | `setFeature(String uri, boolean value)`
`void` | `setNamespaceAware(boolean namespaceAware)` Enable and/or disable namspace handling.
`void` | `setProperty(String uri, Object value)`
`void` | `setTrimWhitespace(boolean trimWhitespace)` Sets the trim whitespace setting value.
`void` | `skippedEntity(String name)`
`void` | `startDocument()`
`void` | `startElement(String namespaceURI, String localName, String qName, Attributes list)`
`void` | `startPrefixMapping(String prefix, String namespaceURI)`

Constructor Detail

### XmlParser

    public XmlParser()

### XmlParser

    public XmlParser(boolean validating, boolean namespaceAware)

### XmlParser

    public XmlParser(XMLReader reader)

### XmlParser

    public XmlParser(SAXParser parser)

Method Detail

### addTextToNode

    void addTextToNode()

### characters

    public void characters(def buffer, int start, int length)

### endDocument

    public void endDocument()

### endElement

    public void endElement(String namespaceURI, String localName, String qName)

### endPrefixMapping

    public void endPrefixMapping(String prefix)

### getDTDHandler

    public DTDHandler getDTDHandler()

### getDocumentLocator

    public Locator getDocumentLocator()

### getElementName

    Object getElementName(String namespaceURI, String localName, String qName)

### getEntityResolver

    public EntityResolver getEntityResolver()

### getErrorHandler

    public ErrorHandler getErrorHandler()

### getFeature

    public boolean getFeature(String uri)

### getProperty

    public Object getProperty(String uri)

### getXMLReader

    XMLReader getXMLReader()

### ignorableWhitespace

    public void ignorableWhitespace(def buffer, int start, int len)

### isNamespaceAware

    public boolean isNamespaceAware()

  Determine if namspace handling is enabled.
  return:
    true if namespace handling is enabled

### isTrimWhitespace

    public boolean isTrimWhitespace()

  Returns the current trim whitespace setting.
  return:
    true if whitespace will be trimmed

### parse

    public Node parse(File file)

  Parses the content of the given file as XML turning it into a tree of Nodes.
  param:
    file the File containing the XML to be parsed
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### parse

    public Node parse(InputSource input)

  Parse the content of the specified input source into a tree of Nodes.
  param:
    input the InputSource for the XML to parse
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### parse

    public Node parse(InputStream input)

  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
  param:
    input an InputStream containing the XML to be parsed
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### parse

    public Node parse(Reader in)

  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
  param:
    in a Reader to read the XML to be parsed
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### parse

    public Node parse(String uri)

  Parse the content of the specified URI into a tree of Nodes.
  param:
    uri a String containing a uri pointing to the XML to be parsed
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### parseText

    public Node parseText(String text)

  A helper method to parse the given text as XML.
  param:
    text the XML text to parse
  return:
    the root node of the parsed tree of Nodes
  throws:
    SAXException Any SAX exception, possibly
  wrapping another exception.
  throws:
    IOException An IO exception from the parser,
  possibly from a byte stream or character stream supplied by the application.

### processingInstruction

    public void processingInstruction(String target, String data)

### setDTDHandler

    public void setDTDHandler(DTDHandler dtdHandler)

### setDocumentLocator

    public void setDocumentLocator(Locator locator)

### setEntityResolver

    public void setEntityResolver(EntityResolver entityResolver)

### setErrorHandler

    public void setErrorHandler(ErrorHandler errorHandler)

### setFeature

    public void setFeature(String uri, boolean value)

### setNamespaceAware

    public void setNamespaceAware(boolean namespaceAware)

  Enable and/or disable namspace handling.
  param:
    namespaceAware the new desired value

### setProperty

    public void setProperty(String uri, Object value)

### setTrimWhitespace

    public void setTrimWhitespace(boolean trimWhitespace)

  Sets the trim whitespace setting value.
  param:
    trimWhitespace the desired setting value

### skippedEntity

    public void skippedEntity(String name)

### startDocument

    public void startDocument()

### startElement

    public void startElement(String namespaceURI, String localName, String qName, Attributes list)

### startPrefixMapping

    public void startPrefixMapping(String prefix, String namespaceURI)