com.ihr.xbrl.util

## Class XMLTools

- java.lang.Object
- - com.ihr.xbrl.util.XMLTools

-     public class XMLTools
      extends java.lang.Object

  Static helper methods to deal with common XML issues.
  Author:
    Ignacio

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.util.Comparator<javax.xml.namespace.QName>` | `QNameComparatorINSTANCE` The Q name comparator instance.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XMLTools()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addChildElementImpl(net.sf.saxon.tree.linked.ElementImpl tableModel, net.sf.saxon.tree.linked.ElementImpl tableSet)` Adds the child element impl.
    `static net.sf.saxon.tree.linked.ElementImpl` | `createElementNode(net.sf.saxon.om.NamePool np, java.lang.String prefix, java.lang.String namespace, java.lang.String localname)` Creates the element node.
    `static net.sf.saxon.om.MutableNodeInfo` | `createTextNode(net.sf.saxon.Configuration conf, java.lang.String value)` Creates the text node.
    `static boolean` | `effectiveBooleanValue(net.sf.saxon.value.AtomicValue atVal)` Effective boolean value.
    `static java.lang.String` | `getNamespaceURIforPrefix(java.lang.String pfx, net.sf.saxon.s9api.XdmNode node)` Gets the namespace ur ifor prefix.
    `static javax.xml.namespace.QName` | `javaxQName(net.sf.saxon.s9api.QName qname)` Creates a new javax QName from a saxon QName.
    `static javax.xml.namespace.QName` | `javaxQName(net.sf.saxon.value.QNameValue qname)` Creates a new javax QName from a saxon QName.
    `static javax.xml.namespace.QName` | `javaxQName(java.lang.String value, net.sf.saxon.s9api.XdmNode node)` Constructs a QName using the lexical representation in the value argument and namespaces defined at node.
    `static javax.xml.namespace.QName` | `javaxQName(net.sf.saxon.om.StructuredQName qname)` Javax q name.
    `static javax.xml.namespace.QName` | `javaxQName(net.sf.saxon.s9api.XdmNode node)` Constructs a QName from an attribute XdmNode or an element that is well known to have a QName content.
    `static java.lang.String` | `jClark(javax.xml.namespace.QName q)` This should be the same as QName.toString() but we may want to implement this consistently for other QNames too so we have own own implementation
    `static void` | `jdomCreateAttributeNode(org.jdom.Element el, java.lang.String attributeName, javax.xml.namespace.QName value)` Jdom create attribute node.
    `static java.lang.Object` | `jdomNode(net.sf.saxon.s9api.XdmNode node)` Jdom node.
    `static java.util.Collection<?>` | `jdomNodeSet(net.sf.saxon.s9api.XdmSequenceIterator iter)` Jdom node set.
    `static java.util.Collection<?>` | `jdomNodeSet(net.sf.saxon.s9api.XdmValue descriptionNodes)` Jdom node set.
    `static javax.xml.namespace.QName` | `qnameFromJClark(java.lang.String clarkQName)` builds back a QName instance from the jClark representation.
    `static java.lang.String` | `qnameToString(javax.xml.namespace.QName q)` Serializes the QName as a string using the prefix:localName if prefix is not defined then this method uses {namespace}:localName .
    `static java.lang.String` | `qnameToString2(javax.xml.namespace.QName q)` Serializes the QName as a string using the prefix:localName if prefix is not defined then this method uses localName only if prefix is null, the returned value is QName(?).
    `static net.sf.saxon.value.QNameValue` | `qnameValue(javax.xml.namespace.QName q)` Qname value.
    `static java.lang.String` | `removeNamespaceDeclarations(java.lang.String string)` This method removes namespace declarations from the incoming string.
    `static java.lang.String` | `replaceExpressionsWithVariableValues(java.lang.String xpathExpression, TraceVariablesBind variableBinds)` This method will replace variables in the xpathExpression with the evaluated values from the TraceVariablesBind The variable comparison is not perfect because at this time the input xpath expression is just a string so there is no way to determine the right namespace link to variables in the variables has a prefix.
    `static net.sf.saxon.om.FingerprintedQName` | `saxonFpQName(javax.xml.namespace.QName qName)` Saxon fp q name.
    `static net.sf.saxon.s9api.QName` | `saxonQName(javax.xml.namespace.QName qname)` Creates a new saxon QName from a javax QName.
    `static net.sf.saxon.s9api.QName` | `saxonQName(net.sf.saxon.value.QNameValue attribute)` Saxon q name.
    `static void` | `setElementImplQNameValue(net.sf.saxon.tree.linked.ElementImpl element, javax.xml.namespace.QName value)` Sets the element impl q name value.
    `static void` | `setJDomElementValue(org.jdom.Element jdomNode, java.lang.Object value)` Sets to jdomNode the value after the required conversions depending on the object type.
    `static net.sf.saxon.om.StructuredQName` | `structuredQName(javax.xml.namespace.QName qName)` Structured q name.
    `static java.util.Collection<?>` | `textToJDomNodes(java.lang.String string)` Returns a collection of text and Element nodes transforming the content of the string parameter accordingly.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### QNameComparatorINSTANCE

          public static java.util.Comparator<javax.xml.namespace.QName> QNameComparatorINSTANCE

      The Q name comparator instance.

  - ### Constructor Detail

    - #### XMLTools

          public XMLTools()

  - ### Method Detail

    - #### saxonQName

          public static net.sf.saxon.s9api.QName saxonQName(javax.xml.namespace.QName qname)

      Creates a new saxon QName from a javax QName.
      Parameters:
        `qname` - in the javax library
      Returns:
        QName in the Saxon library

    - #### javaxQName

          public static javax.xml.namespace.QName javaxQName(net.sf.saxon.s9api.QName qname)

      Creates a new javax QName from a saxon QName.
      Parameters:
        `qname` - in the Saxon library
      Returns:
        QName in the javax library

    - #### javaxQName

          public static javax.xml.namespace.QName javaxQName(net.sf.saxon.value.QNameValue qname)

      Creates a new javax QName from a saxon QName.
      Parameters:
        `qname` - in the Saxon value library
      Returns:
        QName in the javax library

    - #### javaxQName

          public static javax.xml.namespace.QName javaxQName(net.sf.saxon.s9api.XdmNode node)

      Constructs a QName from an attribute XdmNode or an element that is well known to have a QName content.
      Parameters:
        `node` - the node
      Returns:
        the q name

    - #### javaxQName

          public static javax.xml.namespace.QName javaxQName(java.lang.String value,
                                             net.sf.saxon.s9api.XdmNode node)

      Constructs a QName using the lexical representation in the value argument and namespaces defined at node.
      Parameters:
        `value` - the value
        `node` - the node
      Returns:
        the javax.xml.namespace. q name

    - #### effectiveBooleanValue

          public static boolean effectiveBooleanValue(net.sf.saxon.value.AtomicValue atVal)

      Effective boolean value.
      Parameters:
        `atVal` - the at val
      Returns:
        true, if successful

    - #### qnameValue

          public static net.sf.saxon.value.QNameValue qnameValue(javax.xml.namespace.QName q)

      Qname value.
      Parameters:
        `q` - the q
      Returns:
        the q name value

    - #### jdomNodeSet

          public static java.util.Collection<?> jdomNodeSet(net.sf.saxon.s9api.XdmValue descriptionNodes)

      Jdom node set.
      Parameters:
        `descriptionNodes` - the description nodes
      Returns:
        the collection

    - #### jdomNodeSet

          public static java.util.Collection<?> jdomNodeSet(net.sf.saxon.s9api.XdmSequenceIterator iter)

      Jdom node set.
      Parameters:
        `iter` - the iter
      Returns:
        the collection

    - #### jdomNode

          public static java.lang.Object jdomNode(net.sf.saxon.s9api.XdmNode node)

      Jdom node.
      Parameters:
        `node` - the node
      Returns:
        org.jdom.Element or org.jdom.Text depending on the node type

    - #### jdomCreateAttributeNode

          public static void jdomCreateAttributeNode(org.jdom.Element el,
                                     java.lang.String attributeName,
                                     javax.xml.namespace.QName value)

      Jdom create attribute node.
      Parameters:
        `el` - the el
        `attributeName` - the attribute name
        `value` - the value

    - #### getNamespaceURIforPrefix

          public static java.lang.String getNamespaceURIforPrefix(java.lang.String pfx,
                                                  net.sf.saxon.s9api.XdmNode node)

      Gets the namespace ur ifor prefix.
      Parameters:
        `pfx` - the pfx
        `node` - the node
      Returns:
        the namespace ur ifor prefix

    - #### javaxQName

          public static javax.xml.namespace.QName javaxQName(net.sf.saxon.om.StructuredQName qname)

      Javax q name.
      Parameters:
        `qname` - the qname
      Returns:
        the q name

    - #### structuredQName

          public static net.sf.saxon.om.StructuredQName structuredQName(javax.xml.namespace.QName qName)

      Structured q name.
      Parameters:
        `qName` - the q name
      Returns:
        the structured q name

    - #### saxonFpQName

          public static net.sf.saxon.om.FingerprintedQName saxonFpQName(javax.xml.namespace.QName qName)

      Saxon fp q name.
      Parameters:
        `qName` - the q name
      Returns:
        the fingerprinted q name

    - #### qnameToString

          public static java.lang.String qnameToString(javax.xml.namespace.QName q)

      Serializes the QName as a string using the prefix:localName

      if prefix is not defined then this method uses {namespace}:localName

      .

      Parameters:
        `q` - the q
      Returns:
        String

    - #### jClark

          public static java.lang.String jClark(javax.xml.namespace.QName q)

      This should be the same as QName.toString() but we may want to implement this consistently for other QNames too so we have own own implementation
      Parameters:
        `q` - the q
      Returns:
        James Clark representation of a QName

    - #### qnameFromJClark

          public static javax.xml.namespace.QName qnameFromJClark(java.lang.String clarkQName)

      builds back a QName instance from the jClark representation.
      Parameters:
        `clarkQName` - the clark q name
      Returns:
        a QName from the Clark representation

    - #### qnameToString2

          public static java.lang.String qnameToString2(javax.xml.namespace.QName q)

      Serializes the QName as a string using the prefix:localName

      if prefix is not defined then this method uses localName only

      if prefix is null, the returned value is QName(?).

      Parameters:
        `q` - the q
      Returns:
        String

    - #### setJDomElementValue

          public static void setJDomElementValue(org.jdom.Element jdomNode,
                                 java.lang.Object value)

      Sets to jdomNode the value after the required conversions depending on the object type.

      if value is null, jdom node content is unset.
      if value is a String, BigDecimal, BigInteger, Double, Float, Boolean, QName or net.sf.saxon.s9api.QName the value is converted to a string using the toString or toPlainString methods. if valule is a QName, namespaces may be added to the node. if value is not any of the previously value types, the toString method is used on the value object.

      Parameters:
        `jdomNode` - as org.jdom.Element
        `value` - as Object

    - #### textToJDomNodes

          public static java.util.Collection<?> textToJDomNodes(java.lang.String string)
                                                         throws org.jdom.JDOMException

      Returns a collection of text and Element nodes transforming the content of the string parameter accordingly.
      Parameters:
        `string` - the string
      Returns:
        the collection
      Throws:
        `org.jdom.JDOMException` - the JDOM exception

    - #### removeNamespaceDeclarations

          public static java.lang.String removeNamespaceDeclarations(java.lang.String string)

      This method removes namespace declarations from the incoming string. This method is useful only to show raw XML on a small text container in the user interface.
      Parameters:
        `string` - this is a valid XML string including xmlns:XXXXX="whatever" declarations.
      Returns:
        a string that contains all xmlns:XXXXX="whatever" declarations stripped off.

    - #### replaceExpressionsWithVariableValues

          public static java.lang.String replaceExpressionsWithVariableValues(java.lang.String xpathExpression,
                                                              TraceVariablesBind variableBinds)

      This method will replace variables in the xpathExpression with the evaluated values from the TraceVariablesBind The variable comparison is not perfect because at this time the input xpath expression is just a string so there is no way to determine the right namespace link to variables in the variables has a prefix. So this method shall be used only to prepare a formatted text output of for GUI purposes.
      Parameters:
        `xpathExpression` - the xpath expression
        `variableBinds` - the variable binds
      Returns:
        the string

    - #### saxonQName

          public static net.sf.saxon.s9api.QName saxonQName(net.sf.saxon.value.QNameValue attribute)

      Saxon q name.
      Parameters:
        `attribute` - the attribute
      Returns:
        the net.sf.saxon.s9api. q name

    - #### createTextNode

          public static net.sf.saxon.om.MutableNodeInfo createTextNode(net.sf.saxon.Configuration conf,
                                                       java.lang.String value)

      Creates the text node.
      Parameters:
        `conf` - the conf
        `value` - the value
      Returns:
        the mutable node info

    - #### setElementImplQNameValue

          public static void setElementImplQNameValue(net.sf.saxon.tree.linked.ElementImpl element,
                                      javax.xml.namespace.QName value)

      Sets the element impl q name value.
      Parameters:
        `element` - the element
        `value` - the value

    - #### createElementNode

          public static net.sf.saxon.tree.linked.ElementImpl createElementNode(net.sf.saxon.om.NamePool np,
                                                               java.lang.String prefix,
                                                               java.lang.String namespace,
                                                               java.lang.String localname)

      Creates the element node.
      Parameters:
        `np` - the np
        `prefix` - the prefix
        `namespace` - the namespace
        `localname` - the localname
      Returns:
        the element impl

    - #### addChildElementImpl

          public static void addChildElementImpl(net.sf.saxon.tree.linked.ElementImpl tableModel,
                                 net.sf.saxon.tree.linked.ElementImpl tableSet)

      Adds the child element impl.
      Parameters:
        `tableModel` - the table model
        `tableSet` - the table set