yarfraw.utils
Class XMLUtils

java.lang.Object
  extended by yarfraw.utils.XMLUtils

public class XMLUtils
extends Object


Method Summary
static String emptyIfNull(String str)
          Return empty string if input is null.
static String getAttributeValue(Node element, QName name)
          Get the attribute value of the attribute that matches the specified QName.
static String getAttributeValue(Node element, String attributeLocalName)
          Get the attribute value of the attribute that matches the specified localName.
static String getAttributeValue(Node element, String attributeLocalName, String namespaceUri)
          Get the attribute value of the attribute that matches the specified localName and NamespaceUri
static Node getChildrenNodeByName(Node parent, String localName)
          Get a single Children node of the input parent using a localName
static List<Node> getChildrenNodesByName(Node parent, String localName)
          Get a list of Children nodes of the input parent using a localName
static Element getElementByLocalName(List<Element> elements, String localName)
          Search through the input element list and return the FIRST element that matches the localName.
static Element getElementByNS(List<Element> elements, String namespaceURI, String localName)
          Search through the input element list and return the first element that matches both input the namespaceURI and the localName.
static QName getQName(Node n)
          Construct a QName object using a node's localName and NamespaceUri
static Document parseXml(InputSource source, boolean validating, boolean ignoringComments)
          Parses xml to a Document object.
static Document parseXml(InputStream stream, boolean validating, boolean ignoringComments)
          Parses an xml stream to a Document object.
static Document parseXml(String xml, boolean validating, boolean ignoringComments)
          Parses an xml string to a Document object.
static boolean same(QName qn1, QName qn2)
           
static String transformWithXsl(String xslt, String xml)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseXml

public static Document parseXml(String xml,
                                boolean validating,
                                boolean ignoringComments)
                         throws SAXException,
                                IOException,
                                ParserConfigurationException
Parses an xml string to a Document object.

Parameters:
xml - - xml to be parsed
validating - - see DocumentBuilderFactory
ignoringComments - - see DocumentBuilderFactory
Returns:
a W3 DOM object representation of the input string
Throws:
SAXException
IOException
ParserConfigurationException

parseXml

public static Document parseXml(InputStream stream,
                                boolean validating,
                                boolean ignoringComments)
                         throws SAXException,
                                IOException,
                                ParserConfigurationException
Parses an xml stream to a Document object.

Parameters:
stream - - xml to be parsed
validating - - see DocumentBuilderFactory
ignoringComments - - see DocumentBuilderFactory
Returns:
a W3 DOM object representation of the input string
Throws:
SAXException
IOException
ParserConfigurationException

parseXml

public static Document parseXml(InputSource source,
                                boolean validating,
                                boolean ignoringComments)
                         throws SAXException,
                                IOException,
                                ParserConfigurationException
Parses xml to a Document object.

Parameters:
source - - xml source to be parsed
validating - - see DocumentBuilderFactory
ignoringComments - - see DocumentBuilderFactory
Returns:
a W3 DOM object representation of the input string
Throws:
SAXException
IOException
ParserConfigurationException

getElementByNS

public static Element getElementByNS(List<Element> elements,
                                     String namespaceURI,
                                     String localName)
Search through the input element list and return the first element that matches both input the namespaceURI and the localName.

Parameters:
namespaceURI - - namespaceURI of the element to be search for
localName - - localName of the element
Returns:
- null if no matching element is found, the matching element otherwise.

getElementByLocalName

public static Element getElementByLocalName(List<Element> elements,
                                            String localName)
Search through the input element list and return the FIRST element that matches the localName.

Parameters:
localName - - localName of the element
Returns:
- null if no matching element is found, the matching element otherwise.

same

public static boolean same(QName qn1,
                           QName qn2)

emptyIfNull

public static String emptyIfNull(String str)
Return empty string if input is null.

Parameters:
str -
Returns:

getAttributeValue

public static String getAttributeValue(Node element,
                                       QName name)
Get the attribute value of the attribute that matches the specified QName.

Parameters:
element - - the element to be searched on.
name - -
Returns:
- the value of the specified attribute, null if the attribute is not found.

getAttributeValue

public static String getAttributeValue(Node element,
                                       String attributeLocalName)
Get the attribute value of the attribute that matches the specified localName.

Parameters:
element - - the element to be searched on.
name - -
Returns:
- the value of the specified attribute, null if the attribute is not found.

getAttributeValue

public static String getAttributeValue(Node element,
                                       String attributeLocalName,
                                       String namespaceUri)
Get the attribute value of the attribute that matches the specified localName and NamespaceUri

Parameters:
element - - the element to be searched on.
name - -
Returns:
- the value of the specified attribute, null if the attribute is not found.

getQName

public static QName getQName(Node n)
Construct a QName object using a node's localName and NamespaceUri

Parameters:
n - - a DOM node
Returns:
- a new QName object that has input localName as it's localName and input NamespaceUri as its NamespaceUri.

getChildrenNodesByName

public static List<Node> getChildrenNodesByName(Node parent,
                                                String localName)
Get a list of Children nodes of the input parent using a localName

Parameters:
parent - - the parent node
localName - - local name of the children to be searched for
Returns:
- all children nodes that matches the input localName.

getChildrenNodeByName

public static Node getChildrenNodeByName(Node parent,
                                         String localName)
Get a single Children node of the input parent using a localName

Parameters:
parent - - the parent node
localName - - local name of the children to be searched for
Returns:
- the FIRST children node that matches the input localName.

transformWithXsl

public static String transformWithXsl(String xslt,
                                      String xml)
                               throws YarfrawException
Throws:
YarfrawException


Copyright © 2008. All Rights Reserved.