BeanIO 1.2.3

org.beanio.parser.xml
Class XmlNodeUtil

java.lang.Object
  extended by org.beanio.parser.xml.XmlNodeUtil

public class XmlNodeUtil
extends Object

Utility class for working with a document object model and XmlDefinition's.

Since:
1.1
Author:
Kevin Seim

Method Summary
static Element findChild(Node parent, XmlDefinition definition, int offset)
          Finds the Nth matching child of a DOM element.
static Element findSibling(Element sibling, XmlDefinition definition)
          Returns a sibling element that matches a given definition, or null if no match is found.
static String getAttribute(Element element, XmlDefinition definition)
          Returns the value of an attribute for an element.
static String getText(Node node)
          Returns the child text from a DOM node.
static String getText(Node node, XmlDefinition definition)
          Returns the child text from a DOM node after adjusting for any node wrapping.
static boolean isNil(Element element)
          Tests if an element is nil.
static Element unwrap(Element parent, XmlDefinition definition)
          Unwraps an XML element when a wrapper is configured for the given XML definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unwrap

public static Element unwrap(Element parent,
                             XmlDefinition definition)
Unwraps an XML element when a wrapper is configured for the given XML definition. Otherwise, just returns parent.

Parameters:
parent - the parent XML element to unwrap
definition - the definition of the XML node
Returns:
the wrapper child element if found, or null if not, or the parent if the XML node is not wrapped

isNil

public static boolean isNil(Element element)
Tests if an element is nil.

Parameters:
element - the element to test
Returns:
true if the element is nil

getAttribute

public static String getAttribute(Element element,
                                  XmlDefinition definition)
Returns the value of an attribute for an element.

Parameters:
element - the element to check
definition - the definition of the attribute to retrieve from the element
Returns:
the defined attribute value, or null if the attribute was not found on the element

getText

public static String getText(Node node,
                             XmlDefinition definition)
Returns the child text from a DOM node after adjusting for any node wrapping.

Parameters:
node - the node to parse
definition - the definition of the text node
Returns:
the node text, or null if the node did not contain any text

getText

public static String getText(Node node)
Returns the child text from a DOM node.

Parameters:
node - the node to parse
Returns:
the node text, or null if the node did not contain any text

findSibling

public static Element findSibling(Element sibling,
                                  XmlDefinition definition)
Returns a sibling element that matches a given definition, or null if no match is found.

Parameters:
sibling - the sibling DOM element to begin the search
definition - the node to search for
Returns:
the matching element, or null if not found

findChild

public static Element findChild(Node parent,
                                XmlDefinition definition,
                                int offset)
Finds the Nth matching child of a DOM element.

Parameters:
parent - the parent DOM node
definition - the node definition to search for
offset - the occurrence of the matching node
Returns:
the matching element, or null if no match is found

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim