Class XmlElement

    • Constructor Detail

      • XmlElement

        public XmlElement​(Element element)
    • Method Detail

      • attributeAsBoolean

        public boolean attributeAsBoolean​(String attribute)
                                   throws XsylumException
        Get the value of the attribute as a boolean. Returns true for "true", "1", "yes", "y" ignoring case, else returns false.
        Throws:
        XsylumException - if the attribute cannot be found
      • attributeAsEnum

        public <V extends Enum<V>> V attributeAsEnum​(String attribute,
                                                     Class<V> targetEnum)
                                              throws XsylumException
        Get the value of the attribute as an enum of type V. Returns null if value cannot be parsed to an enum of type V.
        Type Parameters:
        V - enum type
        Throws:
        XsylumException - if the attribute cannot be found
      • attributes

        public Map<String,​String> attributes()
        Builds and returns a map of the element's attributes, else empty map if the element has no attributes.
      • children

        public List<XmlElement> children()
        Returns the element's children, else empty list if the element has no children.
      • element

        public Element element()
        Returns the underlying element.
      • get

        public XmlElement get​(int index)
        Returns the XmlElement at the index, else null if none can be found or the node at the index is not an element
      • hasAttribute

        public boolean hasAttribute​(String attribute)
        Returns whether the element contains the attribute.
      • hasAttributes

        public boolean hasAttributes()
        Returns whether the element contains attributes.
      • hasChild

        public boolean hasChild​(String name)
        Returns whether the element contains any child elements with the name.
      • name

        public String name()
        Returns the element's name.
      • toXml

        public String toXml()
        Returns a XML representation of the element, including its attributes and value.
      • value

        public String value()
        Returns the text value of the element.
      • valueAsBoolean

        public boolean valueAsBoolean()
        Get the element value as a boolean. Returns true for "true", "1", "yes", "y" ignoring case, else returns false.
      • valueAsDouble

        public double valueAsDouble()
        Get the element value as a double.
        Throws:
        NumberFormatException - if the value is not a valid double
      • valueAsEnum

        public <V extends Enum<V>> V valueAsEnum​(Class<V> targetEnum)
        Get the element value as an enum of type V. Returns null if value cannot be parsed to an enum of type V.
        Type Parameters:
        V - enum type
      • valueAsInt

        public int valueAsInt()
        Get the element value as an integer.
        Throws:
        NumberFormatException - if the value is not a valid int
      • valueAsLong

        public long valueAsLong()
        Get the element value as a long.
        Throws:
        NumberFormatException - if the value is not a valid long