public class XmlCombiner extends Object
The merging algorithm is as follows:
First direct subelements of selected node are examined.
The elements from both trees with matching keys are paired.
Based on selected behavior the content of the paired elements is then merged.
Finally the paired elements are recursively combined. Any not paired elements are appended.
You can control merging behavior using 'combine.self'
and 'combine.children' attributes.
The merging algorithm was inspired by similar functionality in Plexus Utils.
| Modifier and Type | Class and Description |
|---|---|
static interface |
XmlCombiner.Filter
Allows to filter the result of the merging.
|
| Constructor and Description |
|---|
XmlCombiner()
Creates XML combiner using default
DocumentBuilder. |
XmlCombiner(DocumentBuilder documentBuilder) |
XmlCombiner(DocumentBuilder documentBuilder,
List<String> keyAttributeNames) |
XmlCombiner(DocumentBuilder documentBuilder,
String keyAttributeNames)
Creates XML combiner using given document builder and an id attribute name.
|
XmlCombiner(List<String> keyAttributeNames) |
XmlCombiner(String idAttributeName)
Creates XML combiner using given attribute as an id.
|
| Modifier and Type | Method and Description |
|---|---|
Document |
buildDocument()
Return the result of the merging process.
|
void |
buildDocument(OutputStream out)
Stores the result of the merging process.
|
void |
buildDocument(Path path)
Stores the result of the merging process.
|
void |
combine(Document document)
Combine given document.
|
void |
combine(Element element)
Combine given element.
|
void |
combine(InputStream stream)
Combine given input stream.
|
void |
combine(Path file)
Combine given file.
|
static void |
main(String[] args) |
void |
setFilter(XmlCombiner.Filter filter)
Sets the filter.
|
public XmlCombiner() throws ParserConfigurationException
DocumentBuilder.ParserConfigurationException - when DocumentBuilder creation failspublic XmlCombiner(DocumentBuilder documentBuilder)
public XmlCombiner(String idAttributeName) throws ParserConfigurationException
ParserConfigurationExceptionpublic XmlCombiner(List<String> keyAttributeNames) throws ParserConfigurationException
ParserConfigurationExceptionpublic XmlCombiner(DocumentBuilder documentBuilder, String keyAttributeNames)
public XmlCombiner(DocumentBuilder documentBuilder, List<String> keyAttributeNames)
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, TransformerException
public void setFilter(XmlCombiner.Filter filter)
public void combine(Path file) throws SAXException, IOException
file - file to combineSAXExceptionIOExceptionpublic void combine(InputStream stream) throws SAXException, IOException
stream - input stream to combineSAXExceptionIOExceptionpublic void combine(Document document)
document - document to combinepublic void combine(Element element)
element - element to combinepublic Document buildDocument()
public void buildDocument(OutputStream out) throws TransformerException
TransformerExceptionpublic void buildDocument(Path path) throws TransformerException, FileNotFoundException
Copyright © 2021 Atteo. All rights reserved.