Class MXml


  • public class MXml
    extends Object
    • Constructor Detail

      • MXml

        public MXml()
    • Method Detail

      • getValue

        public static String getValue​(Element root,
                                      boolean inner)
        Returns the text value of a node.
        Parameters:
        root - The element where you need the text value from
        inner - If true all inner elements are parsed and the text appended
        Returns:
        null if root is null or the text of the element
      • getValue

        public static String getValue​(Element root,
                                      MXml.ValueListener listener)
        Returns the text value of a node. The listener manipulates the output for different inner notes.
        Parameters:
        root -
        listener -
        Returns:
        null if the root is null or the text
      • getLocalElements

        public static NodeList getLocalElements​(Element root,
                                                String name)
        Returns a list of elements with this name in the given root element on the first level only.
        Parameters:
        root -
        name -
        Returns:
        null if the root or name is null else the list of nodes
      • getLocalElements

        public static NodeList getLocalElements​(Element root)
        Returns a list of all elements in the given root element on the first level only.
        Parameters:
        root -
        Returns:
        null if the root is null otherwise the list of nodes
      • getLocalElementIterator

        public static MXml.ElementIterator getLocalElementIterator​(Element root,
                                                                   String name)
        Returns an iterator of elements with this name in the given root element on the first level only.
        Parameters:
        root -
        name -
        Returns:
        every time an iterator - never null
      • getLocalElementIterator

        public static MXml.ElementIterator getLocalElementIterator​(Element root)
        Returns an iterator of all elements in the given root element on the first level only.
        Parameters:
        root -
        Returns:
        iterator of the requested elements
      • getElementByPath

        public static Element getElementByPath​(Element root,
                                               String path)
        Returns the first found element by path. Available search definitions are slash and brackets, e.g. "/root/somenode/number[3]/name" or "/root/somenode/filter@key=value/name"
        Parameters:
        root -
        path -
        Returns:
        null if root or path is null or the element is not found
      • getElementsByPath

        public static void getElementsByPath​(Element root,
                                             String path,
                                             List<Element> list)
        Returns the first found element by path. Available search definitions are slash and brackets, e.g. "/root/somenode/number[3]/name" or "/root/somenode/filter@key=value/name" Add an amp before a node to collect all the nodes between too, e.g. "/root/somenode/&filter@key=value/name"
        Parameters:
        root - Start element
        path - Path to go
        list - Result list (findings will be added)
      • getPathAsString

        public static String getPathAsString​(Node in)
        Returns the path to the node as string representation, separated with slashes.
        Parameters:
        in -
        Returns:
        an empty string if the node is null
      • createDocument

        public static Document createDocument()
                                       throws Exception
        Create and return a empty xml document.
        Returns:
        xml model
        Throws:
        Exception
      • encode

        public static String encode​(String _in)
        Encode the default problematic characters in a string to store it in a xml value.
        Parameters:
        _in -
        Returns:
        encoded string
      • unicodeEncode

        public static String unicodeEncode​(String _in)
        Encodes the amp and all characters greater then 255 to unicode representation with amp and hash signs.
        Parameters:
        _in -
        Returns:
        encoded string
      • decode

        public static String decode​(String _in)
        Decodes a string with encoded characters to a java string.
        Parameters:
        _in -
        Returns:
        decoded string
      • dump

        public static String dump​(Node element)
        Prints information - most technical - of the xml element and its childs and returns it as string. Use this function for debugging (debugger).
        Parameters:
        element -
        Returns:
        a dump representation
      • dump

        public static void dump​(PrintStream o,
                                Node element)
        Prints information - most technical - of the xml element and its childs to the stream.
        Parameters:
        o -
        element -
      • innerXml

        public static String innerXml​(Node node)
        Returns the inner XML Structure as string with all tag definitions.
        Parameters:
        node -
        Returns:
        inner structure as string
      • innerXml

        public static String innerXml​(Node node,
                                      boolean instructions)
        Returns the inner XML Structure as string with all tag definitions.
        Parameters:
        node -
        instructions - set to false to ignore processing instructions (on the first level)
        Returns:
        null if the node is null otherwise the innerXml as text
      • trim

        public static void trim​(Element element)
        Remove white spaces in the text nodes.
        Parameters:
        element -
      • carveOut

        public static void carveOut​(Element element)
        Remove the element from his parent but append the children instead if it into the parent node - on the same position.
        Parameters:
        element -
      • normalizeName

        public static String normalizeName​(String key)
        Normalize the name of attributes or node names. Allowed characters are (a-z, A-Z, 0-9, - _ .) all other characters are replaced with _
        Parameters:
        key -
        Returns:
        normalized key or null if the key is null.
      • removeTags

        public static String removeTags​(String txt)
      • removeHtmlTags

        public static String removeHtmlTags​(String txt)