Package com.thingworx.common.utils
Class XMLUtilities
- java.lang.Object
-
- com.thingworx.common.utils.XMLUtilities
-
@ThingworxExtensionApiClass(since={6,6}, canInstantiate=true) public final class XMLUtilities extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ENABLE_XXE
-
Constructor Summary
Constructors Constructor Description XMLUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static org.w3c.dom.Document
createDocument()
static org.w3c.dom.Document
createDocument(java.lang.String contentStr)
static javax.xml.parsers.DocumentBuilderFactory
createDocumentBuilderFactory()
static org.w3c.dom.Document
createDocumentFromStream(java.io.InputStream is)
static org.w3c.dom.Element
getChildElementByTagName(org.w3c.dom.Element node, java.lang.String element)
static java.util.ArrayList<org.w3c.dom.Element>
getChildElements(org.w3c.dom.Element node)
static java.util.ArrayList<org.w3c.dom.Element>
getChildElementsByTagName(org.w3c.dom.Element node, java.lang.String element)
static java.lang.String
getChildElementValueByTagName(org.w3c.dom.Element node, java.lang.String element)
static java.lang.String
getChildElementValueByTagNameWithNull(org.w3c.dom.Element node, java.lang.String element)
static org.w3c.dom.Document
getDocument(java.io.InputStream in)
static org.w3c.dom.Document
getDocument(java.io.Reader in)
static org.w3c.dom.Element
getElementByTagName(org.w3c.dom.Element node, java.lang.String element)
static java.lang.String
getElementValueByTagName(org.w3c.dom.Element node, java.lang.String element)
static java.lang.String
getNodeValue(org.w3c.dom.Node node)
Will return the String value of the given node.static java.lang.String
getTextContent(org.w3c.dom.Node node)
static java.lang.String
outputXMLDoc(org.w3c.dom.Document doc)
Used for XML POST and PUTstatic void
outputXMLDoc(org.w3c.dom.Document doc, java.io.OutputStream output)
static void
outputXMLDoc(org.w3c.dom.Document doc, java.io.Writer output)
static java.lang.String
outputXMLDocFormatted(org.w3c.dom.Document doc)
static void
outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.OutputStream output)
static void
outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.OutputStream output, java.lang.Integer indent)
Deprecated.indent is no longer supportedstatic void
outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.Writer output)
static java.lang.String
outputXMLDocFormatted(org.w3c.dom.Document doc, java.lang.Integer indent)
Deprecated.indent is no longer supportedstatic void
outputXMLDocFormatted(org.w3c.dom.Document outdoc, java.lang.String filepath)
static void
setNodeValue(org.w3c.dom.Node nodeTarget, java.lang.String value)
-
-
-
Method Detail
-
createDocumentBuilderFactory
@ThingworxExtensionApiMethod(since={6,6}) public static javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory() throws javax.xml.parsers.ParserConfigurationException
- Throws:
javax.xml.parsers.ParserConfigurationException
- If an error occurs
-
createDocumentFromStream
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Document createDocumentFromStream(java.io.InputStream is) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for importing Entity from file and attachments
-
createDocument
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Document createDocument()
-
createDocument
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Document createDocument(java.lang.String contentStr) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Currently used for service requests
-
getDocument
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Document getDocument(java.io.InputStream in) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Currently used for importing default entities for High Availability (HA) and getDocument(File).
-
getDocument
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Document getDocument(java.io.Reader in) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Currently used for converting to Primitive and storing data.
-
outputXMLDoc
@ThingworxExtensionApiMethod(since={6,6}) public static void outputXMLDoc(org.w3c.dom.Document doc, java.io.OutputStream output) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for generating unformatted XML.
-
outputXMLDoc
@ThingworxExtensionApiMethod(since={6,6}) public static void outputXMLDoc(org.w3c.dom.Document doc, java.io.Writer output) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for generating unformatted XML.
-
outputXMLDoc
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String outputXMLDoc(org.w3c.dom.Document doc)
Used for XML POST and PUT
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={8,1}) public static void outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.Writer output) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for generating formatted XML for Source Export operations. The XML will be indented using four spaces, line feed for new line, expand empty elements, add new lines for element attributes, format CDATA.
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={6,6}, deprecatedSince={8,1}) @Deprecated public static void outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.OutputStream output, java.lang.Integer indent) throws java.lang.Exception
Deprecated.indent is no longer supported- Throws:
java.lang.Exception
- If an error occurs- See Also:
outputXMLDocFormatted(Document, OutputStream)
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={8,1}) public static void outputXMLDocFormatted(org.w3c.dom.Document doc, java.io.OutputStream output) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for exporting source as zip- See Also:
outputXMLDocFormatted(Document, Writer)
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={6,6}, deprecatedSince={8,1}) public static java.lang.String outputXMLDocFormatted(org.w3c.dom.Document doc, java.lang.Integer indent)
Deprecated.indent is no longer supported- See Also:
outputXMLDocFormatted(Document)
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={8,1}) public static java.lang.String outputXMLDocFormatted(org.w3c.dom.Document doc)
- See Also:
outputXMLDocFormatted(Document, Writer)
-
outputXMLDocFormatted
@ThingworxExtensionApiMethod(since={8,1}) public static void outputXMLDocFormatted(org.w3c.dom.Document outdoc, java.lang.String filepath) throws java.lang.Exception
- Throws:
java.lang.Exception
- If an error occurs
Used for exporting source control entities- See Also:
outputXMLDocFormatted(Document, Writer)
-
getTextContent
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String getTextContent(org.w3c.dom.Node node)
-
getElementValueByTagName
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String getElementValueByTagName(org.w3c.dom.Element node, java.lang.String element)
-
getChildElementByTagName
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Element node, java.lang.String element)
-
getChildElements
@ThingworxExtensionApiMethod(since={6,6}) public static java.util.ArrayList<org.w3c.dom.Element> getChildElements(org.w3c.dom.Element node)
-
getChildElementsByTagName
@ThingworxExtensionApiMethod(since={6,6}) public static java.util.ArrayList<org.w3c.dom.Element> getChildElementsByTagName(org.w3c.dom.Element node, java.lang.String element)
-
getChildElementValueByTagNameWithNull
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String getChildElementValueByTagNameWithNull(org.w3c.dom.Element node, java.lang.String element)
-
getChildElementValueByTagName
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String getChildElementValueByTagName(org.w3c.dom.Element node, java.lang.String element)
-
getElementByTagName
@ThingworxExtensionApiMethod(since={6,6}) public static org.w3c.dom.Element getElementByTagName(org.w3c.dom.Element node, java.lang.String element)
-
getNodeValue
@ThingworxExtensionApiMethod(since={6,6}) public static java.lang.String getNodeValue(org.w3c.dom.Node node)
Will return the String value of the given node. This method accepts Node's of typeNode.ELEMENT_NODE
,Node.ATTRIBUTE_NODE
,Node.TEXT_NODE
andNode.CDATA_SECTION_NODE
. All other Node types will return an empty string.Note: As of 7.2.0, if an
Node.ELEMENT_NODE
node has childNode.TEXT_NODE
nodes containing only whitespace characters (like newlines or tabs) the node will be treated as an empty string. For example, ifNode.TEXT_NODE
node only contains "\n\t\t\t", the value will be "".- Parameters:
node
- The DOM node that you want to retrieve the text value from- Returns:
- The value of the given DOM node
-
setNodeValue
@ThingworxExtensionApiMethod(since={6,6}) public static void setNodeValue(org.w3c.dom.Node nodeTarget, java.lang.String value)
-
-