Class XmlHelper


  • public class XmlHelper
    extends Object
    A utility class to help with some common/basic XML manipulation tasks.
    Since:
    8.0
    • Constructor Detail

      • XmlHelper

        public XmlHelper()
    • Method Detail

      • addToSaml2Extensions

        public XmlObject addToSaml2Extensions​(XmlObject targetDocument,
                                              String xml)
        Adds the given xml to the Extensions element (creating the Extensions, if needed) of the SAML 2.0 protocol XML document.
        Parameters:
        targetDocument - a SAML 2.0 protocol XML document (i.e. ResponseDocument or AuthnRequestDocument)
        xml - the XML to add to the Extensions
        Returns:
        a reference to the XmlObject representing the newly added XML element, which can be further manipulated and the changes will be reflected in the SAML 2.0 protocol XML document
      • setAttribute

        public void setAttribute​(XmlObject target,
                                 String attributeName,
                                 String attributeValue)
        Sets an attribute on the given xml element
        Parameters:
        target - the xml element on which to set the attribute
        attributeName - name of the attribute
        attributeValue - value of the attribute
      • setAttribute

        public void setAttribute​(XmlObject target,
                                 String attributeNamespace,
                                 String attributeName,
                                 String attributeValue)
        Sets an attribute on the given xml element
        Parameters:
        target - the xml element on which to set the attribute
        attributeNamespace - namespace of the attribute
        attributeName - name of the attribute
        attributeValue - value of the attribute
      • parse

        public XmlObject parse​(String xml)
        Parses the xml string into an XmlObject.
        Parameters:
        xml - the xml string
        Returns:
        the XmlObject
        Throws:
        IllegalArgumentException - if any problems are encountered parsing the string
      • addAsLastChild

        public XmlObject addAsLastChild​(XmlObject target,
                                        XmlObject child)
        Adds child as the last child element of target.
        Parameters:
        target - the xml element to which the child will be added
        child - the xml element that will be added
        Returns:
        a reference to the child element in the new context
      • addAsFirstChild

        public XmlObject addAsFirstChild​(XmlObject target,
                                         XmlObject child)
        Adds child as the first child element of target.
        Parameters:
        target - the xml element to which the child will be added
        child - the xml element that will be added
        Returns:
        a reference to the child element in the new context
      • getFirstChild

        public XmlObject getFirstChild​(XmlObject xmlObject)
        Returns the first child element of the given xml.
        Parameters:
        xmlObject - the parent xml element
        Returns:
        the first child element of the given XmlObject or null, if it has no child elements.
      • getChildren

        public List<XmlObject> getChildren​(XmlObject xmlObject)
        Returns all the child elements of the given xml.
        Parameters:
        xmlObject - the parent xml element
        Returns:
        a list of child elements