public final class XMLUtilities extends Object
TransformerFactory
instances.
(This is based on similar utility methods in ph-commons.)
| Modifier and Type | Field and Description |
|---|---|
static String |
SAXON_TRANSFORMER_FACTORY_CLASS_NAME
Explicit name of the SAXON 9.X TransformerFactoryImpl Class, as used by the up-conversion extensions
|
| Constructor and Description |
|---|
XMLUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static TransformerFactory |
createJAXPTransformerFactory()
Creates an instance of the currently specified JAXP
TransformerFactory, ensuring
that the result supports the DOMSource.FEATURE and DOMResult.FEATURE
features. |
static DocumentBuilder |
createNSAwareDocumentBuilder()
Creates a (namespace-aware) DOM
DocumentBuilder, throwing a SnuggleRuntimeException
if such a thing cannot be created/configured. |
static TransformerFactory |
createSaxonTransformerFactory()
Explicitly creates a Saxon 9
TransformerFactory, as used by the up-conversion
extensions. |
static String |
extractTextElementValue(Element textElement)
Trivial convenience method to extract the value of a (text) Element, coping with the
possibility that text child Nodes may not have been coalesced.
|
static boolean |
isSaxonAvailable() |
static boolean |
isXMLName(String string) |
static boolean |
isXMLNCName(String string) |
static void |
requireFeature(TransformerFactory transformerFactory,
String feature) |
static String |
serializeNode(Node node,
SerializationSpecifier serializationOptions)
Serializes the given
Node to a well-formed external parsed entity. |
static String |
serializeNode(StylesheetManager stylesheetManager,
Node node,
SerializationSpecifier serializationOptions)
Serializes the given
Node to a well-formed external parsed entity. |
static String |
serializeNodeChildren(StylesheetManager stylesheetManager,
Node node,
SerializationSpecifier serializationOptions)
Serializes the
children of given Node to a well-formed external parsed entity. |
static void |
setIndentation(Transformer transformer,
int indent)
Helper to turn on indentation for a
Transformer that works correctly for
both Saxon and Xalan. |
static boolean |
supportsXSLT20(Transformer tranformer) |
static boolean |
supportsXSLT20(TransformerFactory tranformerFactory)
Tests whether the given
TransformerFactory is known to support XSLT 2.0. |
public static final String SAXON_TRANSFORMER_FACTORY_CLASS_NAME
public static TransformerFactory createJAXPTransformerFactory()
TransformerFactory, ensuring
that the result supports the DOMSource.FEATURE and DOMResult.FEATURE
features.public static void requireFeature(TransformerFactory transformerFactory, String feature)
public static boolean isSaxonAvailable()
public static TransformerFactory createSaxonTransformerFactory()
TransformerFactory, as used by the up-conversion
extensions.public static boolean supportsXSLT20(TransformerFactory tranformerFactory)
TransformerFactory is known to support XSLT 2.0.
(Currently, this involves checking for a suitable version of Saxon; this will change once more processors become available.)
public static boolean supportsXSLT20(Transformer tranformer)
public static void setIndentation(Transformer transformer, int indent)
Transformer that works correctly for
both Saxon and Xalan.transformer - Transformer to configureindent - required indentation, where 0 or more provides indentation and negative
numbers turns indentation off.public static DocumentBuilder createNSAwareDocumentBuilder()
DocumentBuilder, throwing a SnuggleRuntimeException
if such a thing cannot be created/configured.public static String extractTextElementValue(Element textElement)
textElement - public static String serializeNode(Node node, SerializationSpecifier serializationOptions)
Node to a well-formed external parsed entity.
(If the given Node is an Element or a Document then the result
will be a well-formed XML String.)node - DOM Node to serialize.serializationOptions - XML serialization optionspublic static String serializeNode(StylesheetManager stylesheetManager, Node node, SerializationSpecifier serializationOptions)
Node to a well-formed external parsed entity.
(If the given Node is an Element or a Document then the result
will be a well-formed XML String.)
(This may use an XSLT 2.0 stylesheet to help with named entities, hence the requirement for a
StylesheetManager).
stylesheetManager - used to help compile and cache stylesheets used in this process.node - DOM Node to serialize.serializationOptions - XML serialization optionspublic static String serializeNodeChildren(StylesheetManager stylesheetManager, Node node, SerializationSpecifier serializationOptions)
children of given Node to a well-formed external parsed entity.
(This uses a little XSLT stylesheet to help, hence the requirement for a StylesheetManager).
stylesheetManager - used to help compile and cache stylesheets used in this process.node - DOM Node to serialize.serializationOptions - XML serialization optionspublic static boolean isXMLName(String string)
public static boolean isXMLNCName(String string)
Copyright © 2008–2026 The University of Edinburgh. All rights reserved.