Class XmlElement

java.lang.Object
org.libxmq.imp.xml.XmlNode
org.libxmq.imp.xml.XmlElement
All Implemented Interfaces:
XMQElement, XMQNode

public class XmlElement extends XmlNode implements XMQElement
An element. Attributes are kept in source order. Namespace declarations (xmlns and xmlns:prefix) are not attributes, they are stored in the nsDef list, like in libxml2.
  • Field Details

    • XML_NS

      public static final XmlNs XML_NS
      The predefined xml namespace.
  • Constructor Details

    • XmlElement

      public XmlElement(String name)
      Create an element.
      Parameters:
      name - The local name, ie without a namespace prefix.
  • Method Details

    • type

      public XMQNodeType type()
      Description copied from class: XmlNode
      Returns the type of this node.
      Specified by:
      type in interface XMQNode
      Specified by:
      type in class XmlNode
      Returns:
      The node type.
    • ns

      public XmlNs ns()
      Returns the namespace of the element.
      Specified by:
      ns in interface XMQElement
      Returns:
      The namespace or null.
    • setNs

      public void setNs(XMQNS ns)
      Set the namespace of the element.
      Specified by:
      setNs in interface XMQElement
      Parameters:
      ns - The namespace or null.
    • nsDefs

      public List<XmlNs> nsDefs()
      Returns the namespace declarations on this element, in source order.
      Returns:
      The live list of declarations.
    • declareNs

      public XmlNs declareNs(String prefix, String uri)
      Declare a namespace on this element, like libxml2 xmlNewNs. If the prefix is already declared on this element, the existing declaration is returned unchanged, also when its uri differs (libxml2 xmlNewNs returns NULL instead).
      Specified by:
      declareNs in interface XMQElement
      Parameters:
      prefix - The prefix, null for the default namespace.
      uri - The namespace uri.
      Returns:
      The new or the existing namespace declaration.
    • searchNs

      public XmlNs searchNs(String prefix)
      Search the namespace declared for the prefix on this element or its ancestors, like libxml2 xmlSearchNs.
      Specified by:
      searchNs in interface XMQElement
      Parameters:
      prefix - The prefix, null for the default namespace.
      Returns:
      The namespace or null.
    • attributes

      public List<XmlAttr> attributes()
      Returns the attributes, in source order.
      Returns:
      The live list of attributes.
    • addAttribute

      public XmlAttr addAttribute(XMQAttr a)
      Add an attribute last, like libxml2 xmlNewProp.
      Specified by:
      addAttribute in interface XMQElement
      Parameters:
      a - The attribute.
      Returns:
      The attribute.
    • setAttribute

      public XmlAttr setAttribute(String name, String value)
      Add or replace an attribute with a text value.
      Specified by:
      setAttribute in interface XMQElement
      Parameters:
      name - The attribute name.
      value - The value.
      Returns:
      The attribute.
    • removeAttribute

      public void removeAttribute(XMQAttr a)
      Remove an attribute.
      Specified by:
      removeAttribute in interface XMQElement
      Parameters:
      a - The attribute to remove.
    • attribute

      public XmlAttr attribute(String name)
      Find an attribute without a namespace by its name.
      Specified by:
      attribute in interface XMQElement
      Parameters:
      name - The name.
      Returns:
      The attribute or null.
    • attributeByFullName

      public XmlAttr attributeByFullName(String full_name)
      Find an attribute by its full name, ie prefix:name.
      Specified by:
      attributeByFullName in interface XMQElement
      Parameters:
      full_name - The full name.
      Returns:
      The attribute or null.
    • attributeValue

      public String attributeValue(String name)
      Returns the value of an attribute.
      Specified by:
      attributeValue in interface XMQElement
      Parameters:
      name - The attribute name.
      Returns:
      The value or null if the attribute does not exist.
    • elements

      public List<XMQElement> elements()
      Returns the element children.
      Specified by:
      elements in interface XMQElement
      Returns:
      A new list of the child elements.
    • element

      public XmlElement element(String name)
      Returns the first child element with the given name.
      Specified by:
      element in interface XMQElement
      Parameters:
      name - The local name.
      Returns:
      The element or null.
    • fullName

      public String fullName()
      Description copied from class: XmlNode
      Returns the full name, ie prefix:name if the node has a namespace with a prefix.
      Specified by:
      fullName in interface XMQNode
      Overrides:
      fullName in class XmlNode
      Returns:
      The full name.