Class XmlService
java.lang.Object
org.apache.maven.api.xml.XmlService
- Direct Known Subclasses:
DefaultXmlService
Comprehensive service interface for XML operations including node creation,
merging, reading, and writing.
This class provides XML merging functionality for Maven's XML handling and specifies the combination modes that control how XML elements are merged.
The merger supports two main types of combinations:
- Children combination: Controls how child elements are combined
- Self combination: Controls how the element itself is combined
Children combination modes (specified by combine.children
attribute):
merge
(default): Merges elements with matching namesappend
: Adds elements as siblings
Self combination modes (specified by combine.self
attribute):
merge
(default): Merges attributes and valuesoverride
: Completely replaces the elementremove
: Removes the element
For complex XML structures, combining can also be done based on:
- ID: Using the
combine.id
attribute - Keys: Using the
combine.keys
attribute with comma-separated key names
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface for building input locations during XML parsing. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Value indicating children should be appended as siblingsstatic final String
Value indicating children should be merged based on element namesstatic final String
Attribute name controlling how child elements are combinedstatic final String
Default mode for combining children DOMs during merge.static final String
Default mode for combining a DOM node during merge.static final String
Attribute name for ID-based combination modestatic final String
Attribute name for key-based combination mode.static final String
Value indicating the element should be mergedstatic final String
Attribute name controlling how the element itself is combinedstatic final String
Value indicating the element should be completely overriddenstatic final String
Value indicating the element should be removed -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract XmlNode
Implementation method for merging two XML nodes.protected abstract XmlNode
doRead
(InputStream input, XmlService.InputLocationBuilder locationBuilder) Implementation method for reading an XML node from an input stream.protected abstract XmlNode
doRead
(Reader reader, XmlService.InputLocationBuilder locationBuilder) Implementation method for reading an XML node from a reader.protected abstract XmlNode
doRead
(XMLStreamReader reader, XmlService.InputLocationBuilder locationBuilder) Implementation method for reading an XML node from an XMLStreamReader.protected abstract void
Implementation method for writing an XML node to a writer.static XmlNode
Convenience method to merge two XML nodes using default settings.static XmlNode
Merges two XML nodes.static XmlNode
read
(InputStream input, XmlService.InputLocationBuilder locationBuilder) Reads an XML node from an input stream.static XmlNode
Reads an XML node from a reader.static XmlNode
read
(Reader reader, XmlService.InputLocationBuilder locationBuilder) Reads an XML node from a reader.static XmlNode
read
(XMLStreamReader reader) Reads an XML node from an XMLStreamReader.static XmlNode
read
(XMLStreamReader reader, XmlService.InputLocationBuilder locationBuilder) Reads an XML node from an XMLStreamReader.static void
Writes an XML node to a writer.
-
Field Details
-
CHILDREN_COMBINATION_MODE_ATTRIBUTE
Attribute name controlling how child elements are combined- See Also:
-
CHILDREN_COMBINATION_MERGE
Value indicating children should be merged based on element names- See Also:
-
CHILDREN_COMBINATION_APPEND
Value indicating children should be appended as siblings- See Also:
-
DEFAULT_CHILDREN_COMBINATION_MODE
Default mode for combining children DOMs during merge. When element names match, the process will try to merge the element data, rather than putting the dominant and recessive elements as siblings.- See Also:
-
SELF_COMBINATION_MODE_ATTRIBUTE
Attribute name controlling how the element itself is combined- See Also:
-
SELF_COMBINATION_OVERRIDE
Value indicating the element should be completely overridden- See Also:
-
SELF_COMBINATION_MERGE
Value indicating the element should be merged- See Also:
-
SELF_COMBINATION_REMOVE
Value indicating the element should be removed- See Also:
-
DEFAULT_SELF_COMBINATION_MODE
Default mode for combining a DOM node during merge. When element names match, the process will try to merge element attributes and values, rather than overriding the recessive element completely.- See Also:
-
ID_COMBINATION_MODE_ATTRIBUTE
Attribute name for ID-based combination mode- See Also:
-
KEYS_COMBINATION_MODE_ATTRIBUTE
Attribute name for key-based combination mode. Value should be a comma-separated list of attribute names.- See Also:
-
-
Constructor Details
-
XmlService
public XmlService()
-
-
Method Details
-
merge
-
merge
-
read
@Nonnull public static XmlNode read(InputStream input, @Nullable XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Reads an XML node from an input stream.- Throws:
XMLStreamException
-
read
Reads an XML node from a reader.- Throws:
XMLStreamException
-
read
@Nonnull public static XmlNode read(Reader reader, @Nullable XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Reads an XML node from a reader.- Throws:
XMLStreamException
-
read
Reads an XML node from an XMLStreamReader.- Throws:
XMLStreamException
-
read
@Nonnull public static XmlNode read(XMLStreamReader reader, @Nullable XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Reads an XML node from an XMLStreamReader.- Throws:
XMLStreamException
-
write
Writes an XML node to a writer.- Throws:
IOException
-
doRead
protected abstract XmlNode doRead(InputStream input, XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Implementation method for reading an XML node from an input stream.- Parameters:
input
- the input stream to read fromlocationBuilder
- optional builder for creating input location objects- Returns:
- the parsed XML node
- Throws:
XMLStreamException
- if there is an error parsing the XML
-
doRead
protected abstract XmlNode doRead(Reader reader, XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Implementation method for reading an XML node from a reader.- Parameters:
reader
- the reader to read fromlocationBuilder
- optional builder for creating input location objects- Returns:
- the parsed XML node
- Throws:
XMLStreamException
- if there is an error parsing the XML
-
doRead
protected abstract XmlNode doRead(XMLStreamReader reader, XmlService.InputLocationBuilder locationBuilder) throws XMLStreamException Implementation method for reading an XML node from an XMLStreamReader.- Parameters:
reader
- the XML stream reader to read fromlocationBuilder
- optional builder for creating input location objects- Returns:
- the parsed XML node
- Throws:
XMLStreamException
- if there is an error parsing the XML
-
doWrite
Implementation method for writing an XML node to a writer.- Parameters:
node
- the XML node to writewriter
- the writer to write to- Throws:
IOException
- if there is an error writing the XML
-
doMerge
Implementation method for merging two XML nodes.- Parameters:
dominant
- the dominant (higher priority) XML noderecessive
- the recessive (lower priority) XML nodechildMergeOverride
- optional override for the child merge mode- Returns:
- the merged XML node, or null if both inputs are null
-