Class KmgXMLUtil


  • public class KmgXMLUtil
    extends Object
    Collection of (static) methods adding to package org.w3c.dom.
    • Method Detail

      • findAttributeValue

        public static int findAttributeValue​(NodeList nodeList,
                                             String attrName,
                                             String attrValue)
        Searches nodeList for the first element elem matching elem.getAttribute(attrName).equals(attrValue).
        Parameters:
        nodeList - e.g. result from Node.getChildNodes()
        attrName - the name of the attribute checked for attrValue
        attrValue - for a match the attribute value equals this parameter
        Returns:
        index of the first element matching or -1 if not found
         int i = KmgXMLUtil.findAttributeValue( nodeList, attrName, attrValue );
         ⇒ i == -1 || nodeList.item(i).getAttribute( attrName ).equals( attrValue )
         
        See Also:
        Node.getChildNodes(), Element.getAttribute(java.lang.String)
      • getAttributeValue

        public static String getAttributeValue​(Node nd,
                                               String attrName)
        Other than Element.getAttribute(java.lang.String) this method can be called on nd of any node type and returns the empty string, if nd is not an Element.
        Parameters:
        nd - can be of any node type
        attrName - the name of the attribute to retrieve
        Returns:
        ((Element)nd).getAttribute(attrName) if nd is an Element or the empty string otherwise
      • getChildElements

        public static Element[] getChildElements​(Node nd)
        Other than Node.getChildNodes() this method only returns nodes of type Element.
        Parameters:
        nd - can be of any node type
        Returns:
        all child nodes of nd which are instanceof Element.
      • formatAttributes

        public static String[] formatAttributes​(Node nd)
        Formats all attributes of nd.
        Parameters:
        nd - can be of any node type
        Returns:
        array of the attributes of nd formatted as string or an empty array if nd has no attributes
        See Also:
        Node.getAttributes()
      • formatChildNodes

        public static String[] formatChildNodes​(Node nd)
        Formats all child nodes of nd.
        Parameters:
        nd - can be of any node type
        Returns:
        array of the child nodes of nd formatted as string or an empty array if nd has no child nodes
        See Also:
        Node.getChildNodes()
      • formatType

        protected static String formatType​(short nodeType)
        Replaces the numerical node type by a descriptive Letter.

        EElement REntityReference DDocument
        AAttribute IEntity TDocumentType
        XText PProcessingInstruction FDocumentFragment
        SCDATASection CComment NNotation
        See Also:
        Constant Field Values, Node.ELEMENT_NODE