com.ibm.commerce.marketing.util

Class XMLHelper

  • java.lang.Object
    • com.ibm.commerce.marketing.util.XMLHelper


  • public class XMLHelper
    extends java.lang.Object
    This class provides a set of utility methods for XML manipulation such as XML parsing based on the predefined XML model.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.String beginTag(java.lang.String tagName, java.lang.String[] attributes, java.lang.String[] values)
      Constructs the beginning tag of an XML Element
      static java.lang.String endTag(java.lang.String tagName)
      Return the end tag of one XML element
      static java.lang.String formatToXMLCompatibleData(java.lang.String text)
      Replaces illegal characters with entity references in XML, which include "&", "<", ">", "'" and """
      static java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String name)
      Returns the value of an attribute
      static org.w3c.dom.Node getChildElementByName(org.w3c.dom.Node node, java.lang.String name)
      Returns a child element of current node
      static java.lang.String getChildElementValue(org.w3c.dom.Element thisNode, java.lang.String childName)
      Helps to find the string value of a Child XML element
      static java.lang.String getChildElementValue(org.w3c.dom.Node thisNode, java.lang.String childName)
      Returns the value of the child element identified by childName parameter
      static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
      Obtains a non-validating document builder for serial re-use by the current thread.
      static java.util.Vector getElementTextValue(org.w3c.dom.Node node, java.lang.String elementTagName)
      This method will return a vector of all possible text values which match the given element tag name in the Node Object.
      static java.lang.String getElementValue(org.w3c.dom.Node node)
      Returns the value of the current element.
      static org.w3c.dom.Document getXMLDocument(java.lang.String xmlString)
      Generator the XML Document object based on the XML String input.
      static XMLizable initializeXMLizableObject(org.w3c.dom.Node node)
      Initializes XMLizable object based on the "impl" attribute
      static java.lang.String simpleValueTag(java.lang.String tag, java.lang.String value)
      Returns an enclosed tag String.
      static java.lang.String startTag(java.lang.String tagName)
      Return the start tag of one XML element.
      static java.lang.String startTag(java.lang.String tagName, java.lang.String attributeName, java.lang.String attributeValue)
      Return the start tag with one attribute.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright
        See Also:
        Constant Field Values
      • TEXT_AMPERSAND

        public static final java.lang.String TEXT_AMPERSAND
        Ampersand in XML presentation.
        See Also:
        Constant Field Values
      • TEXT_DOUBLE_QUOTE

        public static final java.lang.String TEXT_DOUBLE_QUOTE
        Double quote in XML presentation
        See Also:
        Constant Field Values
      • TEXT_DOUBLE_QUOTE_FOR_BLAZE

        public static final java.lang.String TEXT_DOUBLE_QUOTE_FOR_BLAZE
        Double quote for XML presentation and Blaze presentation.
        See Also:
        Constant Field Values
      • TEXT_LEFT_ANGLE_BRACKET

        public static final java.lang.String TEXT_LEFT_ANGLE_BRACKET
        Left angle bracket in XML presentation.
        See Also:
        Constant Field Values
      • TEXT_RIGHT_ANGLE_BRACKET

        public static final java.lang.String TEXT_RIGHT_ANGLE_BRACKET
        Right angle bracket in XML presentation.
        See Also:
        Constant Field Values
      • TEXT_SINGLE_QUOTE

        public static final java.lang.String TEXT_SINGLE_QUOTE
        Single quote in XML presentation.
        See Also:
        Constant Field Values
    • Method Detail

      • startTag

        public static java.lang.String startTag(java.lang.String tagName)
        Return the start tag of one XML element.
        Parameters:
        tagName - is the name of tag.
        Returns:
        String the startTag in string format.
      • startTag

        public static java.lang.String startTag(java.lang.String tagName,
                                                java.lang.String attributeName,
                                                java.lang.String attributeValue)
        Return the start tag with one attribute.
        Parameters:
        tagName - is a tag name.
        attributeName - is the attribute name.
        attributeValue - is the attribute value.
        Returns:
        String the startTag in string format.
      • endTag

        public static java.lang.String endTag(java.lang.String tagName)
        Return the end tag of one XML element
        Parameters:
        tagName - is the name of tag
        Returns:
        endTag in string format
      • getChildElementValue

        public static java.lang.String getChildElementValue(org.w3c.dom.Element thisNode,
                                                            java.lang.String childName)
        Helps to find the string value of a Child XML element
        Parameters:
        thisNode - Node the parent node
        childName - String the name of the child element
        Returns:
        the value of that child element
      • getChildElementValue

        public static java.lang.String getChildElementValue(org.w3c.dom.Node thisNode,
                                                            java.lang.String childName)
        Returns the value of the child element identified by childName parameter
        Parameters:
        thisNode - the current XML node
        childName - the name of the child element
        Returns:
        the value of the child element
      • getElementTextValue

        public static java.util.Vector getElementTextValue(org.w3c.dom.Node node,
                                                           java.lang.String elementTagName)
        This method will return a vector of all possible text values which match the given element tag name in the Node Object.
        Parameters:
        node - is the current XML node.
        elementTagName - is the name of element tag in string format.
        Returns:
        the list of element text value.
      • beginTag

        public static java.lang.String beginTag(java.lang.String tagName,
                                                java.lang.String[] attributes,
                                                java.lang.String[] values)
        Constructs the beginning tag of an XML Element
        Parameters:
        tagName - String name of the tag
        attributes - String attribute names
        values - String attribute values
        Returns:
        String the complete tag
      • getDocumentBuilder

        public static final javax.xml.parsers.DocumentBuilder getDocumentBuilder()
                                                                          throws javax.xml.parsers.ParserConfigurationException
        Obtains a non-validating document builder for serial re-use by the current thread. Use this method to avoid constructing a new document builder factory and document builder.
        Returns:
        the document builder.
        Throws:
        javax.xml.parsers.ParserConfigurationException
      • getXMLDocument

        public static org.w3c.dom.Document getXMLDocument(java.lang.String xmlString)
        Generator the XML Document object based on the XML String input.
        Parameters:
        xmlString - xml string to be built to document.
        Returns:
        org.w3c.dom.Document.
      • getElementValue

        public static java.lang.String getElementValue(org.w3c.dom.Node node)
        Returns the value of the current element.
        Parameters:
        node - is the node in a DOM tree.
        Returns:
        node's value from a DOM tree.
      • getAttributeValue

        public static java.lang.String getAttributeValue(org.w3c.dom.Node node,
                                                         java.lang.String name)
        Returns the value of an attribute
        Parameters:
        node - is the node in a DOM tree
        name - name of the attribute
        Returns:
        value of the attribute
      • getChildElementByName

        public static org.w3c.dom.Node getChildElementByName(org.w3c.dom.Node node,
                                                             java.lang.String name)
        Returns a child element of current node
        Parameters:
        node - is the node in a DOM tree
        name - name of the child element
        Returns:
        child element as a node in the DOM tree
      • simpleValueTag

        public static java.lang.String simpleValueTag(java.lang.String tag,
                                                      java.lang.String value)
        Returns an enclosed tag String. For example: <tag>value</tag>
        Parameters:
        tag - name of the tag
        value - value of the element
        Returns:
        String of a simple enclosed tag
      • initializeXMLizableObject

        public static XMLizable initializeXMLizableObject(org.w3c.dom.Node node)
                                                   throws DeXMLizationException
        Initializes XMLizable object based on the "impl" attribute
        Parameters:
        node - XML node that represent the XML object
        Returns:
        an XMLizable object from a node in the DOM tree
        Throws:
        DeXMLizationException - when the DeXMLization fails due to class instantiation problems or DeXMLization problems
      • formatToXMLCompatibleData

        public static java.lang.String formatToXMLCompatibleData(java.lang.String text)
        Replaces illegal characters with entity references in XML, which include "&", "<", ">", "'" and """
        Parameters:
        text - the original text
        Returns:
        the text with all the illegal characters replaced by entity references