Class NameValueHandler

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.bitlet.weupnp.NameValueHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class NameValueHandler extends DefaultHandler
A simple SAX handler that is used to parse XML name value pairs in the form <name>value</name>
See Also:
  • Constructor Details

    • NameValueHandler

      public NameValueHandler(Map<String,String> nameValue)
      Creates a new instance of a NameValueHandler, storing values in the supplied map
      Parameters:
      nameValue - the map to store name-value pairs in
  • Method Details

    • startElement

      public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
      Receive notification of the start of an element. Caches the element as currentElement, so that it will be stored as a map key when the corresponding value will be read.
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Parameters:
      uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
      localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
      qName - The qualified name (with prefix), or the empty string if qualified names are not available.
      attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • endElement

      public void endElement(String uri, String localName, String qName) throws SAXException
      Receive notification of the end of an element. It is used to reset currentElement when the XML node is closed. Note: this works only when the data we are interested in does not contain child nodes. Based on a patch provided by christophercyll and attached to issue #4: http://code.google.com/p/weupnp/issues/detail?id=4
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Parameters:
      uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
      localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
      qName - The qualified name (with prefix), or the empty string if qualified names are not available.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
    • characters

      public void characters(char[] ch, int start, int length) throws SAXException
      Receive notification of character data inside an element. Stores the characters as value, using currentElement as a key
      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Parameters:
      ch - The characters.
      start - The start position in the character array.
      length - The number of characters to use from the character array.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also: