Class XMLUtil
- Since:
- 3.4
- Author:
- Eike Stepper
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilderstatic DocumentBuilderCreates a namespace-aware parser that rejects DTD declarations and disables external entities, XInclude, and entity expansion.static inthandleChildElements(Element rootElement, XMLUtil.ElementHandler handler) static inthandleElements(NodeList nodeList, XMLUtil.ElementHandler handler) static inthandleElementsByTagName(Element rootElement, String tagName, XMLUtil.ElementHandler handler) static DocumentloadDocument(DocumentBuilder documentBuilder, File file) static ElementloadRootElement(DocumentBuilder documentBuilder, File file) static voidpreprocessConditions(Document document, Map<String, String> parameters) Preprocesses conditional attributes in a namespace-aware DOM without an explicit container for resolvingStringConverters.static voidpreprocessConditions(Document document, Map<String, String> parameters, IManagedContainer container) Preprocesses conditional attributes in a namespace-aware DOM.
-
Method Details
-
createDocumentBuilder
- Throws:
ParserConfigurationException
-
createSecureDocumentBuilder
Creates a namespace-aware parser that rejects DTD declarations and disables external entities, XInclude, and entity expansion.- Returns:
- a secure non-validating document builder
- Throws:
ParserConfigurationException- if the parser does not support the required security features- Since:
- 3.31
-
loadRootElement
- Throws:
Exception
-
loadDocument
public static Document loadDocument(DocumentBuilder documentBuilder, File file) throws SAXException, IOException - Throws:
SAXExceptionIOException
-
handleElements
public static int handleElements(NodeList nodeList, XMLUtil.ElementHandler handler) throws Exception - Throws:
Exception
-
handleChildElements
public static int handleChildElements(Element rootElement, XMLUtil.ElementHandler handler) throws Exception - Throws:
Exception
-
handleElementsByTagName
public static int handleElementsByTagName(Element rootElement, String tagName, XMLUtil.ElementHandler handler) throws Exception - Throws:
Exception
-
preprocessConditions
Preprocesses conditional attributes in a namespace-aware DOM without an explicit container for resolvingStringConverters. SeepreprocessConditions(Document, Map, IManagedContainer)for the condition syntax and processing details.- Parameters:
document- the document to preprocessparameters- the configuration parameters used bytrueandblank, and queried by exact key forset- Throws:
IllegalArgumentException- if an operator or expandedtruevalue is invalid, or if the root element is excluded- Since:
- 3.31
-
preprocessConditions
public static void preprocessConditions(Document document, Map<String, String> parameters, IManagedContainer container) Preprocesses conditional attributes in a namespace-aware DOM.Namespace declarations and example: Declare the conditional namespaces on the document element and use their prefixes on condition attributes:
<configuration xmlns:if="urn:org.eclipse.net4j:xml:if" xmlns:unless="urn:org.eclipse.net4j:xml:unless"> <endpoint if:true="@enabled"/> <option if:blank="@optional"/> <debug if:set="@debug"/> <release unless:true="@debug"/> </configuration>Operators and semantics: The supported operators are
true,blank, andset, each available in both namespaces.unlessnegates the corresponding operator.trueexpands its value using the supplied parameters and registered StringConverters, trims the result, and accepts only case-insensitivetrueorfalse. An empty or whitespace-only value is false.blankaccepts an expanded null, empty, or whitespace-only value.settests whether a property exists, not the property's contents. An exact parameter key is set even when its value is empty orfalse. Otherwise, the value names a JVM/OMPlatform property, which is set when its value is non-null, including empty andfalsevalues. The exact expression$$$system_property(name)$$$checks the named system property directly. Ordinary converter results and arbitrary non-empty text do not imply that a property is set.
Parameter and property evaluation: The supplied parameters are used to expand
trueandblankvalues. Registered StringConverters are resolved through the supplied container for these values. Forset, an exact parameter key is checked first; if it does not match, the value is interpreted as a JVM/OMPlatform property name, except for the exact system-property expression described above.Combining conditions and removing subtrees: Multiple conditions on one element are combined with AND. Nested elements are processed only while their parents remain included. Excluding an element removes its entire subtree, and all conditional attributes are removed from retained elements.
Namespace awareness and ordinary attributes: The DOM must have been parsed with namespace awareness enabled for the namespace-qualified conditions to be recognized. This method expands values used to evaluate conditions only; it does not expand ordinary attributes.
- Parameters:
document- the document to preprocessparameters- the configuration parameters used bytrueandblank, and queried by exact key forsetcontainer- the container used to resolve StringConverters intrueandblankvalues- Throws:
IllegalArgumentException- if an operator or expandedtruevalue is invalid, or if the root element is excluded- Since:
- 3.31
-