public class XmlUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
AUTO_RELOAD_KEY |
static int |
DEFAULT_XSLT_VERSION |
static XMLEventFactory |
EVENT_FACTORY |
static String |
INCLUDE_FIELD_DEFINITION_BY_DEFAULT_KEY |
static XMLInputFactory |
INPUT_FACTORY |
static String |
NAMESPACE_AWARE_BY_DEFAULT_KEY |
static XMLOutputFactory |
OUTPUT_FACTORY |
static XMLOutputFactory |
REPAIR_NAMESPACES_OUTPUT_FACTORY |
static String |
XPATH_GETROOTNODENAME |
static int |
XSLT_BUFFERSIZE_DEFAULT |
static String |
XSLT_BUFFERSIZE_KEY |
static String |
XSLT_STREAMING_BY_DEFAULT_KEY |
Constructor and Description |
---|
XmlUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
addRootNamespace(String input,
String namespace) |
static boolean |
attributesEqual(Attribute attribute1,
Attribute attribute2) |
static Document |
buildDomDocument(InputSource src,
boolean namespaceAware) |
static Document |
buildDomDocument(InputSource src,
boolean namespaceAware,
boolean resolveExternalEntities) |
static Document |
buildDomDocument(Reader in) |
static Document |
buildDomDocument(Reader in,
boolean namespaceAware) |
static Document |
buildDomDocument(Reader in,
boolean namespaceAware,
boolean resolveExternalEntities) |
static Document |
buildDomDocument(String s)
Convert an XML string to a Document
Creation date: (20-02-2003 8:12:52)
|
static Document |
buildDomDocument(String s,
boolean namespaceAware) |
static Document |
buildDomDocument(String s,
boolean namespaceAware,
boolean resolveExternalEntities) |
static Document |
buildDomDocument(URL url)
Build a Document from a URL
|
static Element |
buildElement(Message s) |
static Element |
buildElement(String s)
Convert an XML string to a Document, then return the root-element.
|
static Element |
buildElement(String s,
boolean namespaceAware)
Convert an XML string to a Document, then return the root-element
|
static Node |
buildNode(String s) |
static Node |
buildNode(String s,
boolean namespaceAware)
Convert an XML string to a Document, then return the root-element as a Node
|
static String |
canonicalize(String input) |
static String |
cdataToText(String input) |
static String |
cleanseElementName(String candidateName) |
static String |
convertEndOfLines(String input) |
static String |
copyOfSelect(String input,
String xpath) |
static Transformer |
createTransformer(Source source,
int xsltVersion) |
static Transformer |
createTransformer(String xsltString) |
static Transformer |
createTransformer(String xsltString,
int xsltVersion) |
static Transformer |
createTransformer(URL url) |
static Transformer |
createTransformer(URL url,
int xsltVersion) |
static String |
createXPathEvaluatorSource(Function<String,String> xpathContainerSupplier,
String xpathExpression,
TransformerPool.OutputType outputMethod,
boolean includeXmlDeclaration,
ParameterList params,
boolean stripSpace,
boolean ignoreNamespaces,
int xsltVersion) |
static String |
createXPathEvaluatorSource(String XPathExpression) |
static String |
createXPathEvaluatorSource(String namespaceDefs,
String xPathExpression,
TransformerPool.OutputType outputMethod) |
static String |
createXPathEvaluatorSource(String namespaceDefs,
String XPathExpression,
TransformerPool.OutputType outputMethod,
boolean includeXmlDeclaration) |
static String |
createXPathEvaluatorSource(String namespaceDefs,
String XPathExpression,
TransformerPool.OutputType outputMethod,
boolean includeXmlDeclaration,
ParameterList params) |
static String |
createXPathEvaluatorSource(String namespaceDefs,
String XPathExpression,
TransformerPool.OutputType outputMethod,
boolean includeXmlDeclaration,
ParameterList params,
boolean stripSpace) |
static String |
createXPathEvaluatorSource(String namespaceDefs,
String xpathExpression,
TransformerPool.OutputType outputMethod,
boolean includeXmlDeclaration,
ParameterList params,
boolean stripSpace,
boolean ignoreNamespaces,
String separator,
int xsltVersion) |
static String |
createXPathEvaluatorSource(String xPathExpression,
TransformerPool.OutputType outputMethod) |
static int |
detectXsltVersion(String xsltString) |
static int |
detectXsltVersion(URL xsltUrl) |
static String |
encodeURL(String url)
encodes a url
|
static Collection<String> |
evaluateXPathNodeSet(String input,
String xpathExpr) |
static Map<String,String> |
evaluateXPathNodeSet(String input,
String xpathExpr,
String keyElement,
String valueElement) |
static String |
evaluateXPathNodeSetFirstElement(String input,
String xpathExpr) |
static Double |
evaluateXPathNumber(String input,
String xpathExpr) |
static String |
getAdapterSite(String input,
Map parameters) |
static TransformerPool |
getAddRootNamespaceTransformerPool(String namespace,
boolean omitXmlDeclaration,
boolean indent) |
static int |
getBufSize() |
static TransformerPool |
getChangeRootTransformerPool(String root,
boolean omitXmlDeclaration,
boolean indent) |
static boolean |
getChildTagAsBoolean(Element el,
String tag)
Method getChildTagAsBoolean.
|
static boolean |
getChildTagAsBoolean(Element el,
String tag,
boolean defaultValue)
Method getChildTagAsBoolean.
|
static long |
getChildTagAsLong(Element el,
String tag)
Method getChildTagAsLong.
|
static long |
getChildTagAsLong(Element el,
String tag,
long defaultValue)
Method getChildTagAsLong.
|
static String |
getChildTagAsString(Element el,
String tag)
Method getChildTagAsString.
|
static String |
getChildTagAsString(Element el,
String tag,
String defaultValue)
Method getChildTagAsString.
|
static Collection<Node> |
getChildTags(Element el,
String tag)
Method getChildTags.
|
static TransformerPool |
getCopyOfSelectTransformerPool(String xpath,
boolean omitXmlDeclaration,
boolean indent) |
static TransformerPool |
getDetectXsltVersionTransformerPool() |
static DocumentBuilderFactory |
getDocumentBuilderFactory() |
static DocumentBuilderFactory |
getDocumentBuilderFactory(boolean namespaceAware) |
static Element |
getFirstChildTag(Element el,
String tag)
Method getFirstChildTag.
|
static TransformerPool |
getGetRootNamespaceTransformerPool() |
static TransformerPool |
getGetRootNodeNameTransformerPool() |
static TransformerPool |
getGetXsltConfigTransformerPool() |
static String |
getNamespaceClause(String namespaceDefs) |
static Map<String,String> |
getNamespaceMap(String namespaceDefs) |
static TransformerPool |
getRemoveNamespacesTransformerPool(boolean omitXmlDeclaration,
boolean indent) |
static TransformerPool |
getRemoveUnusedNamespacesTransformerPool(boolean omitXmlDeclaration,
boolean indent) |
static TransformerPool |
getRemoveUnusedNamespacesXslt2TransformerPool(boolean omitXmlDeclaration,
boolean indent) |
static String |
getRootNamespace(String input) |
static SAXParserFactory |
getSAXParserFactory() |
static SAXParserFactory |
getSAXParserFactory(boolean namespaceAware) |
static String |
getStringValue(Element el) |
static String |
getStringValue(Element el,
boolean trimWhitespace) |
static TransformerFactory |
getTransformerFactory() |
static TransformerFactory |
getTransformerFactory(int xsltVersion) |
static TransformerFactory |
getTransformerFactory(int xsltVersion,
ErrorListener errorListener) |
static ValidatorHandler |
getValidatorHandler(Source schemaSource) |
static ValidatorHandler |
getValidatorHandler(URL schemaURL) |
static Map<String,String> |
getVersionInfo() |
static XMLReader |
getXMLReader(ContentHandler handler) |
static XMLReader |
getXMLReader(IScopeProvider scopeProvider) |
static XPathFactory |
getXPathFactory() |
static XPathFactory |
getXPathFactory(int xsltVersion) |
static Map<String,String> |
getXsltConfig(Source source) |
static SAXSource |
inputSourceToSAXSource(InputSource is) |
static SAXSource |
inputSourceToSAXSource(InputSource is,
boolean namespaceAware,
Resource scopeProvider) |
static SAXSource |
inputSourceToSAXSource(Resource resource) |
static int |
interpretXsltVersion(String xsltVersion) |
static boolean |
isAutoReload() |
static boolean |
isIncludeFieldDefinitionByDefault() |
static boolean |
isNamespaceAwareByDefault() |
static boolean |
isWellFormed(Message input,
String root) |
static boolean |
isWellFormed(String input) |
static boolean |
isWellFormed(String input,
String root) |
static boolean |
isXsltStreamingByDefault() |
protected static String |
makeAddRootNamespaceXslt(String namespace,
boolean omitXmlDeclaration,
boolean indent) |
protected static String |
makeChangeRootXslt(String root,
boolean omitXmlDeclaration,
boolean indent) |
protected static String |
makeCopyOfSelectXslt(String xpath,
boolean omitXmlDeclaration,
boolean indent) |
protected static String |
makeDetectXsltVersionXslt() |
protected static String |
makeGetRootNamespaceXslt() |
protected static String |
makeGetXsltConfigXslt() |
protected static String |
makeRemoveNamespacesXslt(boolean omitXmlDeclaration,
boolean indent) |
protected static String |
makeRemoveNamespacesXsltTemplates() |
protected static String |
makeRemoveUnusedNamespacesXslt(boolean omitXmlDeclaration,
boolean indent) |
protected static String |
makeRemoveUnusedNamespacesXslt2(boolean omitXmlDeclaration,
boolean indent) |
static StartElement |
mergeAttributes(StartElement tag,
Iterator<? extends Attribute> attrs,
Iterator<? extends Namespace> nsps,
XMLEventFactory factory)
Like
XMLStreamUtils.mergeAttributes(javax.xml.stream.events.StartElement, java.util.Iterator, javax.xml.stream.XMLEventFactory) but it can
also merge namespaces |
static byte[] |
nodeToByteArray(Node node) |
static byte[] |
nodeToByteArray(Node node,
boolean omitXmlDeclaration) |
static String |
nodeToString(Node node) |
static String |
nodeToString(Node node,
boolean useIndentation) |
static String |
normalizeAttributeValue(String input) |
static String |
normalizeWhitespace(String input) |
static void |
parseNodeSet(String source,
ContentHandler handler)
like
parseXml(String source, ContentHandler handler) , but skips startDocument() and endDocument(). |
static void |
parseXml(InputSource inputSource,
ContentHandler handler) |
static void |
parseXml(InputSource inputSource,
ContentHandler handler,
ErrorHandler errorHandler) |
static void |
parseXml(Resource resource,
ContentHandler handler) |
static void |
parseXml(String source,
ContentHandler handler) |
static String |
removeNamespaces(String input) |
static void |
setTransformerParameters(Transformer t,
Map<String,Object> parameters)
sets all the parameters of the transformer using a Map with parameter values.
|
static String |
skipDocTypeDeclaration(String xmlString) |
static String |
skipXmlDeclaration(String xmlString) |
static String |
source2String(Source source,
boolean removeNamespaces) |
static Source |
stringToSource(String xmlString) |
static Source |
stringToSource(String xmlString,
boolean namespaceAware)
Converts a string containing xml-markup to a Source-object, that can be used as the input of a XSLT-transformer.
|
static Source |
stringToSourceForSingleUse(String xmlString) |
static Source |
stringToSourceForSingleUse(String xmlString,
boolean namespaceAware) |
static String |
toXhtml(Message message) |
static String |
transformXml(Transformer t,
Source s) |
static void |
transformXml(Transformer t,
Source s,
Writer out) |
static String |
transformXml(Transformer t,
String s) |
static String |
transformXml(Transformer t,
String s,
boolean namespaceAware) |
static void |
transformXml(Transformer t,
String s,
Result result) |
public static final int DEFAULT_XSLT_VERSION
public static final String NAMESPACE_AWARE_BY_DEFAULT_KEY
public static final String XSLT_STREAMING_BY_DEFAULT_KEY
public static final String AUTO_RELOAD_KEY
public static final String XSLT_BUFFERSIZE_KEY
public static final int XSLT_BUFFERSIZE_DEFAULT
public static final String INCLUDE_FIELD_DEFINITION_BY_DEFAULT_KEY
public static final String XPATH_GETROOTNODENAME
public static final XMLEventFactory EVENT_FACTORY
public static final XMLInputFactory INPUT_FACTORY
public static final XMLOutputFactory OUTPUT_FACTORY
public static final XMLOutputFactory REPAIR_NAMESPACES_OUTPUT_FACTORY
protected static String makeDetectXsltVersionXslt()
public static TransformerPool getDetectXsltVersionTransformerPool() throws TransformerException
TransformerException
protected static String makeGetXsltConfigXslt()
public static TransformerPool getGetXsltConfigTransformerPool() throws TransformerException
TransformerException
public static Map<String,String> getXsltConfig(Source source) throws TransformerException, IOException
TransformerException
IOException
public static TransformerPool getGetRootNodeNameTransformerPool() throws ConfigurationException
ConfigurationException
protected static String makeRemoveNamespacesXsltTemplates()
protected static String makeRemoveNamespacesXslt(boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getRemoveNamespacesTransformerPool(boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
protected static String makeGetRootNamespaceXslt()
public static TransformerPool getGetRootNamespaceTransformerPool() throws ConfigurationException
ConfigurationException
protected static String makeAddRootNamespaceXslt(String namespace, boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getAddRootNamespaceTransformerPool(String namespace, boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
protected static String makeChangeRootXslt(String root, boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getChangeRootTransformerPool(String root, boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
protected static String makeRemoveUnusedNamespacesXslt(boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getRemoveUnusedNamespacesTransformerPool(boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
protected static String makeRemoveUnusedNamespacesXslt2(boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getRemoveUnusedNamespacesXslt2TransformerPool(boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
protected static String makeCopyOfSelectXslt(String xpath, boolean omitXmlDeclaration, boolean indent)
public static TransformerPool getCopyOfSelectTransformerPool(String xpath, boolean omitXmlDeclaration, boolean indent) throws ConfigurationException
ConfigurationException
public static boolean isNamespaceAwareByDefault()
public static boolean isXsltStreamingByDefault()
public static boolean isIncludeFieldDefinitionByDefault()
public static boolean isAutoReload()
public static int getBufSize()
public static void parseXml(Resource resource, ContentHandler handler) throws IOException, SAXException
IOException
SAXException
public static void parseXml(String source, ContentHandler handler) throws IOException, SAXException
IOException
SAXException
public static void parseNodeSet(String source, ContentHandler handler) throws IOException, SAXException
parseXml(String source, ContentHandler handler)
, but skips startDocument() and endDocument().
Can be used to parse a string and inject its events in an existing SAX event stream.IOException
SAXException
public static void parseXml(InputSource inputSource, ContentHandler handler) throws IOException, SAXException
IOException
SAXException
public static void parseXml(InputSource inputSource, ContentHandler handler, ErrorHandler errorHandler) throws IOException, SAXException
IOException
SAXException
public static XMLReader getXMLReader(ContentHandler handler) throws ParserConfigurationException, SAXException
public static XMLReader getXMLReader(IScopeProvider scopeProvider) throws ParserConfigurationException, SAXException
public static Document buildDomDocument(Reader in) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(Reader in, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(InputSource src, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(InputSource src, boolean namespaceAware, boolean resolveExternalEntities) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(Reader in, boolean namespaceAware, boolean resolveExternalEntities) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(String s) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(String s, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(String s, boolean namespaceAware, boolean resolveExternalEntities) throws DomBuilderException
DomBuilderException
public static Document buildDomDocument(URL url) throws DomBuilderException
DomBuilderException
public static Element buildElement(String s, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Node buildNode(String s, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Node buildNode(String s) throws DomBuilderException
DomBuilderException
public static Element buildElement(String s) throws DomBuilderException
DomBuilderException
public static Element buildElement(Message s) throws DomBuilderException
DomBuilderException
public static String createXPathEvaluatorSource(String xPathExpression, TransformerPool.OutputType outputMethod)
public static String createXPathEvaluatorSource(String namespaceDefs, String xPathExpression, TransformerPool.OutputType outputMethod)
public static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, TransformerPool.OutputType outputMethod, boolean includeXmlDeclaration)
public static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, TransformerPool.OutputType outputMethod, boolean includeXmlDeclaration, ParameterList params)
public static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, TransformerPool.OutputType outputMethod, boolean includeXmlDeclaration, ParameterList params, boolean stripSpace)
public static String createXPathEvaluatorSource(String namespaceDefs, String xpathExpression, TransformerPool.OutputType outputMethod, boolean includeXmlDeclaration, ParameterList params, boolean stripSpace, boolean ignoreNamespaces, String separator, int xsltVersion)
public static String createXPathEvaluatorSource(Function<String,String> xpathContainerSupplier, String xpathExpression, TransformerPool.OutputType outputMethod, boolean includeXmlDeclaration, ParameterList params, boolean stripSpace, boolean ignoreNamespaces, int xsltVersion)
public static Source stringToSource(String xmlString, boolean namespaceAware) throws DomBuilderException
DomBuilderException
public static Source stringToSource(String xmlString) throws DomBuilderException
DomBuilderException
public static Source stringToSourceForSingleUse(String xmlString) throws SAXException
SAXException
public static Source stringToSourceForSingleUse(String xmlString, boolean namespaceAware) throws SAXException
SAXException
public static SAXSource inputSourceToSAXSource(Resource resource) throws SAXException, IOException
SAXException
IOException
public static SAXSource inputSourceToSAXSource(InputSource is) throws SAXException
SAXException
public static SAXSource inputSourceToSAXSource(InputSource is, boolean namespaceAware, Resource scopeProvider) throws SAXException
SAXException
public static int interpretXsltVersion(String xsltVersion)
public static int detectXsltVersion(String xsltString) throws TransformerConfigurationException
public static int detectXsltVersion(URL xsltUrl) throws TransformerConfigurationException
public static Transformer createTransformer(String xsltString) throws TransformerConfigurationException
public static Transformer createTransformer(String xsltString, int xsltVersion) throws TransformerConfigurationException
public static Transformer createTransformer(URL url) throws TransformerConfigurationException
public static Transformer createTransformer(URL url, int xsltVersion) throws TransformerConfigurationException, IOException
public static Transformer createTransformer(Source source, int xsltVersion) throws TransformerConfigurationException
public static TransformerFactory getTransformerFactory()
public static TransformerFactory getTransformerFactory(int xsltVersion)
public static TransformerFactory getTransformerFactory(int xsltVersion, ErrorListener errorListener)
public static DocumentBuilderFactory getDocumentBuilderFactory()
public static DocumentBuilderFactory getDocumentBuilderFactory(boolean namespaceAware)
public static SAXParserFactory getSAXParserFactory()
public static SAXParserFactory getSAXParserFactory(boolean namespaceAware)
public static boolean getChildTagAsBoolean(Element el, String tag)
tag
in the DOM subtree el
.
To determine true or false, the value of the tag is compared case- insensitive with the values
true,
yes, or
on. If it matches,
true
is returned. If not,
false
is returned.
If the tag can not be found, false
is returned.
el
- DOM subtreetag
- Name of tag to findpublic static boolean getChildTagAsBoolean(Element el, String tag, boolean defaultValue)
tag
in the DOM subtree el
.
To determine true or false, the value of the tag is compared case- insensitive with the values
true,
yes, or
on. If it matches,
true
is returned. If not,
false
is returned.
If the tag can not be found, the default-value is returned.
el
- DOM subtreetag
- Name of tag to finddefaultValue
- Default-value in case tag can not
be found.public static long getChildTagAsLong(Element el, String tag)
tag
in the DOM subtree el
.el
- DOM subtreetag
- Name of tag to findpublic static long getChildTagAsLong(Element el, String tag, long defaultValue)
tag
in the DOM subtree el
.el
- DOM subtreetag
- Name of tag to finddefaultValue
- Default-value in case tag can not
be found, or is not numeric.public static String getChildTagAsString(Element el, String tag)
tag
in the DOM subtree el
.el
- DOM subtreetag
- Name of tag to findpublic static String getChildTagAsString(Element el, String tag, String defaultValue)
tag
in the DOM subtree el
.el
- DOM subtreetag
- Name of tag to finddefaultValue
- Default-value in case tag can not
be found.public static Collection<Node> getChildTags(Element el, String tag)
el
- Element where to get children fromtag
- Tag to match. Use '*' to match all tags.org.w3c.dom.Element
.public static Element getFirstChildTag(Element el, String tag)
el
- Element where to get children fromtag
- Tag to matchnull
if no match
found.public static void setTransformerParameters(Transformer t, Map<String,Object> parameters) throws IOException
IOException
- If an IOException occurs.public static String transformXml(Transformer t, String s) throws TransformerException, IOException, SAXException
public static String transformXml(Transformer t, String s, boolean namespaceAware) throws TransformerException, IOException, SAXException
public static void transformXml(Transformer t, String s, Result result) throws TransformerException, SAXException
TransformerException
SAXException
public static String transformXml(Transformer t, Source s) throws TransformerException, IOException
TransformerException
IOException
public static void transformXml(Transformer t, Source s, Writer out) throws TransformerException
TransformerException
public static boolean isWellFormed(String input)
public static String source2String(Source source, boolean removeNamespaces) throws TransformerException
TransformerException
public static String canonicalize(String input) throws IOException
IOException
public static String nodeToString(Node node) throws TransformerException
TransformerException
public static String nodeToString(Node node, boolean useIndentation) throws TransformerException
TransformerException
public static byte[] nodeToByteArray(Node node) throws TransformerException
TransformerException
public static byte[] nodeToByteArray(Node node, boolean omitXmlDeclaration) throws TransformerException
TransformerException
public static StartElement mergeAttributes(StartElement tag, Iterator<? extends Attribute> attrs, Iterator<? extends Namespace> nsps, XMLEventFactory factory)
XMLStreamUtils.mergeAttributes(javax.xml.stream.events.StartElement, java.util.Iterator, javax.xml.stream.XMLEventFactory)
but it can
also merge namespacespublic static String getAdapterSite(String input, Map parameters) throws IOException, SAXException, TransformerException
public static Collection<String> evaluateXPathNodeSet(String input, String xpathExpr) throws DomBuilderException, XPathExpressionException
public static String evaluateXPathNodeSetFirstElement(String input, String xpathExpr) throws DomBuilderException, XPathExpressionException
public static Double evaluateXPathNumber(String input, String xpathExpr) throws DomBuilderException, XPathExpressionException
public static Map<String,String> evaluateXPathNodeSet(String input, String xpathExpr, String keyElement, String valueElement) throws DomBuilderException, XPathExpressionException
public static String toXhtml(Message message) throws IOException
IOException
public static XPathFactory getXPathFactory()
public static XPathFactory getXPathFactory(int xsltVersion)
public static ValidatorHandler getValidatorHandler(URL schemaURL) throws SAXException
SAXException
public static ValidatorHandler getValidatorHandler(Source schemaSource) throws SAXException
SAXException
Copyright © 2023 Frank!Framework. All rights reserved.