Class DOMElem


  • public class DOMElem
    extends java.lang.Object
    an wrapper interface for easy access to XML DOM parser. This require an
    active back-end that does the actual parsing and validation.

    The DOMElem consist of a <name>, <value> and a DOMElem list of <attributes> and
    <children>. The value is a string and can (for convenience) be extracted as different
    primitive values on the interface eg. double or std::vector<double>. Attributes are DOMElem
    that does not have any children. Children are DOMElem that might contain other children.
    • Constructor Detail

      • DOMElem

        public DOMElem​(long cPtr,
                       boolean cMemoryOwn)
    • Method Detail

      • getCPtr

        public static long getCPtr​(DOMElem obj)
      • delete

        public void delete()
      • isName

        public boolean isName​(java.lang.String elemname)
        test if name of this elem equals elemname
        Parameters:
        elemname - [in] string name to test with
        Returns:
        true if elemname equals name of this DOMElem, false otherwise
      • getName

        public java.lang.String getName()
        get name of this DOMElem
        Returns:
        name of DOMElem
      • getValue

        public java.lang.String getValue()
        get string value of this DOMElem
        Returns:
        string value of this elem
      • getValueAsInt

        public int getValueAsInt()
        get value as an integer, throws an exception if this is not an
        int value.
        Returns:
        the int value
      • getValueAsDouble

        public double getValueAsDouble()
        get value as an double floating point, throws an exception if this is not an
        double value.
        Returns:
        the double value
      • getValueAsStringList

        public vector_s getValueAsStringList​(char stringseperator)
        get value as a list of strings, throws an exception if this is not a
        list of strings. The default string seperator is semicolon (;).
        Returns:
        list of strings
      • getValueAsStringList

        public vector_s getValueAsStringList()
        get value as a list of strings, throws an exception if this is not a
        list of strings. The default string seperator is semicolon (;).
        Returns:
        list of strings
      • getValueAsDoubleList

        public vector_d getValueAsDoubleList()
        get value as a list of doubles, throws an exception if this is not a
        list of doubles. The default string seperator is space ( ).
        Returns:
        list of doubles
      • getValueAsDoubleList

        public vector_d getValueAsDoubleList​(int N)
        get value as a list of N doubles, throws an exception if this is not a
        list of N doubles. The default string seperator is space ( ).
        Returns:
        list of N doubles
      • getChild

        public DOMElemPtr getChild​(java.lang.String name,
                                   boolean optional)
        get a child with a specific name. If more children with the same name occur then
        it cannot be guaranteed which is returned. If optional is false then an exception will be
        thrown if the child cannot be found. If optional is true then NULL is returned if child
        is not found.
        Parameters:
        name - [in] name of the child to find
        optional - [in]
        Returns:
        the DOMElem child if found, else either NULL (is optional) or an exception is
        thrown.
      • getChild

        public DOMElemPtr getChild​(java.lang.String name)
        get a child with a specific name. If more children with the same name occur then
        it cannot be guaranteed which is returned. If optional is false then an exception will be
        thrown if the child cannot be found. If optional is true then NULL is returned if child
        is not found.
        Parameters:
        name - [in] name of the child to find

        Returns:
        the DOMElem child if found, else either NULL (is optional) or an exception is
        thrown.
      • getAttribute

        public DOMElemPtr getAttribute​(java.lang.String name,
                                       boolean optional)
        get a attribute with a specific name. If more attributes with the same name occur
        then it cannot be guaranteed which is returned. If optional is false then an exception
        will be thrown if the child cannot be found. If optional is true then NULL is returned if
        child is not found.
        Parameters:
        name - [in] name of the attribute to find
        optional - [in]
        Returns:
        the DOMElem attribute if found, else either NULL (is optional) or an exception is
        thrown.
      • getAttribute

        public DOMElemPtr getAttribute​(java.lang.String name)
        get a attribute with a specific name. If more attributes with the same name occur
        then it cannot be guaranteed which is returned. If optional is false then an exception
        will be thrown if the child cannot be found. If optional is true then NULL is returned if
        child is not found.
        Parameters:
        name - [in] name of the attribute to find

        Returns:
        the DOMElem attribute if found, else either NULL (is optional) or an exception is
        thrown.
      • hasChild

        public boolean hasChild​(java.lang.String name)
        test if this DOMElem has a child by name name.
        Parameters:
        name - [in] name of the child DOMElem
        Returns:
        true if this DOMElem has a child with name name
      • hasChildren

        public boolean hasChildren()
        test if this DOMElem has any children
        Returns:
        true if this DOMElem has any children
      • hasAttribute

        public boolean hasAttribute​(java.lang.String name)
        test if this DOMElem has an attribute by name name.
        Parameters:
        name - [in] name of the attribute DOMElem
        Returns:
        true if this DOMElem has an attribute with name name
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String name)
        Get the value of attribute as a string.
        Parameters:
        name - [in] the name of the attribute.
        Returns:
        the value.
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String name,
                                                  java.lang.String default_value)
        std::string&)
        Parameters:
        default_value - [in] a default value to return if attibute is not found.
      • getAttributeValueAsInt

        public int getAttributeValueAsInt​(java.lang.String name)
        Get the value of attribute as an integer.
        Parameters:
        name - [in] the name of the attribute.
        Returns:
        the value.
      • getAttributeValueAsInt

        public int getAttributeValueAsInt​(java.lang.String name,
                                          int default_value)
        std::string&)
        Parameters:
        default_value - [in] a default value to return if attibute is not found.
      • getAttributeValueAsDouble

        public double getAttributeValueAsDouble​(java.lang.String name)
        Get the value of attribute as an double.
        Parameters:
        name - [in] the name of the attribute.
        Returns:
        the value.
      • getAttributeValueAsDouble

        public double getAttributeValueAsDouble​(java.lang.String name,
                                                double default_value)
        std::string&)
        Parameters:
        default_value - [in] a default value to return if attibute is not found.
      • getValueAsBool

        public boolean getValueAsBool()
        Get the value as a boolean.
        Returns:
        boolean value.
      • getAttributeValueAsBool

        public boolean getAttributeValueAsBool​(java.lang.String name)
        Get the value of attribute as an boolean.
        Parameters:
        name - [in] the name of the attribute.
        Returns:
        the value.
      • getAttributeValueAsBool

        public boolean getAttributeValueAsBool​(java.lang.String name,
                                               boolean default_value)
        std::string&)
        Parameters:
        default_value - [in] a default value to return if attibute is not found.
      • begin

        public DOMElem.Iterator begin()
        Get iterator to first child element.
        Returns:
        iterator.
      • end

        public DOMElem.Iterator end()
        Get iterator to last child element.
        Returns:
        iterator.
      • addChild

        public DOMElemPtr addChild()
        Add a child with an empty name.
        Returns:
        pointer to the new child element.
      • addChild

        public DOMElemPtr addChild​(java.lang.String name)
        Add a child element.
        Parameters:
        name - [in] name of child.
        Returns:
        pointer to the new child element.
      • addAttribute

        public DOMElemPtr addAttribute​(java.lang.String name)
        Add an attribute element.
        Parameters:
        name - [in] name of the attribute.
        Returns:
        pointer to the new attribute.
      • setValue

        public void setValue​(java.lang.String val)
        Set the value of this element.
        Parameters:
        val - [in] new value.
      • setName

        public void setName​(java.lang.String val)
        Set the name of this element.
        Parameters:
        val - [in] new name.
      • setValue

        public void setValue​(boolean val)
        std::string&)
      • setValue

        public void setValue​(int val)
        std::string&)
      • setValue

        public void setValue​(double val)
        std::string&)
      • setValueString

        public void setValueString​(java.lang.String val)
        std::string&)