Documentation of 'tig.xml.DomDoc' Java class
DomDoc
tig.xml

Class DomDoc

  • All Implemented Interfaces:
    GeneralConstants


    public class DomDoc
    extends java.lang.Object
    implements GeneralConstants
    Wrapps a org.w3c.dom.Document, providing easy access to the document's contents.
    Usage of this class is based on the notion of current path of an element, which describes its path to root node, using "/" as separator and the names of the node's ancestors.
    For example, with the XML structure :
    <rootNode>
      <elt1>
        <elt2>
          <elt3/>
        </elt2>
      </elt1>
    </rootNode>
    
    the current path of elt3 is "rootNode/elt1/elt2".
    So you specify which part of the document you want to access with setCurrentPath(), and then use the other methods.
    If the path is not set, it is considered as "", which is the path to root node. So the results are obtained for the whole document.
    • Constructor Summary

      Constructors 
      Constructor and Description
      DomDoc(org.w3c.dom.Document doc)
      Unique constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean belongsToPath(org.w3c.dom.Node node, java.lang.String path)
      Indicates if a node belongs to a given path.
      java.lang.String[][] getAttributesValues(java.lang.String tagName, java.lang.String attributeNames)
      Equivalent to getAttributesValues(String,String[]) when 'attributeNames' contains only element, or when a regular expression is used to designate the attribute names.
      java.lang.String[][] getAttributesValues(java.lang.String tagName, java.lang.String[] attributeNames)
      Method to get the values of tags attributes.
      java.lang.String getAttributeValue(java.lang.String tagName, java.lang.String attributeName)
      Method to get the value of an attribute of a tag of current path.
      java.lang.String getCurrentPath()
      Returns the "current path".
      org.w3c.dom.Document getDocument()
      Returns the Document that this DomDoc is wrapping.
      static java.lang.String getPath(org.w3c.dom.Node node)
      Returns a String representing the path of a node.
      static void main(java.lang.String[] args) 
      void setCurrentPath(java.lang.String path)
      Sets the "current path".
      void setDocument(org.w3c.dom.Document doc)
      Sets the Document that this DomDoc is wrapping.
      void setRegExMode(int regExMode)
      Sets the "regular expression mode" ; see REGEX_XXX constants.
      • Methods inherited from class java.lang.Object

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

      • DomDoc

        public DomDoc(org.w3c.dom.Document doc)
        Unique constructor.
        Parameters:
        doc - the DOM Document used to handle internally the data.
    • Method Detail

      • setCurrentPath

        public void setCurrentPath(java.lang.String path)
        Sets the "current path". See class documentation for more information.
      • getCurrentPath

        public java.lang.String getCurrentPath()
        Returns the "current path". See class documentation for more information.
      • setDocument

        public void setDocument(org.w3c.dom.Document doc)
        Sets the Document that this DomDoc is wrapping. The current path is set to empty String (root node).
      • getDocument

        public org.w3c.dom.Document getDocument()
        Returns the Document that this DomDoc is wrapping.
      • setRegExMode

        public void setRegExMode(int regExMode)
        Sets the "regular expression mode" ; see REGEX_XXX constants.
      • getAttributeValue

        public java.lang.String getAttributeValue(java.lang.String tagName,
                                                  java.lang.String attributeName)
        Method to get the value of an attribute of a tag of current path.
        Convenient if the document contains one and only one tag 'tagName' ; this tag must have an attribute 'attributeName'. Written to directly get a String.
        Example :
          <myXmlDoc>
            ...
            <theTag theAttribute = "theValue">
            ...
          </myXmlDoc>
        The call getAttributeValue(theTag, theAttribute) will return "theValue".

        This method is sensitive to last call to setCurrentPath(String)

        To retrieve attribute values of several tags, or several attribute values of a tag, use getAttributesValues(String,String[]).
        Returns:
        The value of the specified attribute if one is found - Also works if the doc contains several pairs {tag, attribute}. In this case, the first tag encountered is returned.
        Returns null in the following cases :
      • if 'tagName' or 'attributeName' is null ;
      • if the document contains more than one tag 'tagName' ;

      • if there is no such pair {tag, attribute} (tag or attribute not found).
      • getAttributesValues

        public java.lang.String[][] getAttributesValues(java.lang.String tagName,
                                                        java.lang.String[] attributeNames)
                                                 throws java.lang.Exception
        Method to get the values of tags attributes. Return results for tags of the current path.
        This method can be used to retrieve the attribute values of tags named 'tagName'.
        Example :
          <myXmlDoc>
            ...
            <theTag attr1 = "val1.1" attr2 = "val1.2" attr3="val1.3"/>
            <theTag attr1 = "val2.1" attr3="val2.3"/>
            <theTag attr1 = "val3.1" attr2 = "val3.2" attr3="val3.3"/>
            ...
          </myXmlDoc>
          
        The code :
            String[] attributeNames = new String[]{"attr1", "attr2"};
            getAttributesValues("theTag", attributeNames);
          
        will return a String[] containing :
          {
            {"val1.1", "val1.2"},
            {"val2.1", null},
            {"val3.1", "val3.2"}
          }
          
        Returns:
        the list as specified above or null if the document doesn't contain 'tagName' tags.
        If attributes are missing, null is put to the corresponding place of the the resulting array.
        Returns null if parameter 'tagName' is null, if 'attributeNames' is null or empty
        Throws:
        java.lang.Exception
      • getAttributesValues

        public java.lang.String[][] getAttributesValues(java.lang.String tagName,
                                                        java.lang.String attributeNames)
        Equivalent to getAttributesValues(String,String[]) when 'attributeNames' contains only element, or when a regular expression is used to designate the attribute names.
        The most common use of regular expressions is to use a wildcard ('*') to replace any sequence of character. For more details, see documentation of class java.util.regex.Pattern.
        WARNING : the returned array is not filled with 'null' if the match is not found, like in getAttributesValues(String,String[]).
        Example :
          <myXmlDoc>
            ...
            <theTag attr1 = "val1.1" attr2 = "val1.2" attr3="val1.3"/>
            <theTag attr1 = "val2.1" attr3="val2.3"/>
            <theTag attr1 = "val3.1" attr2 = "val3.2" attr3="val3.3"/>
            ...
          </myXmlDoc>
          
        The code :
            getAttributesValues("theTag", "attr*");
          
        will return a String[] containing :
          {
            {"val1.1", "val1.2", "val1.3"},
            {"val2.1", "val2.3"},
            {"val3.1", "val3.2", "val3.3"}
          }
          
      • getPath

        public static java.lang.String getPath(org.w3c.dom.Node node)
        Returns a String representing the path of a node.
        The String is built with the names of the parent nodes separated by "/".
      • belongsToPath

        public static boolean belongsToPath(org.w3c.dom.Node node,
                                            java.lang.String path)
        Indicates if a node belongs to a given path.
      • main

        public static void main(java.lang.String[] args)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.