Вставка узла в первый дочерний элемент корневого элемента XML с использованием Java - PullRequest
0 голосов
/ 18 января 2019
Comparing the Source XML with Destination XML and want to add the missing tags to the Destination XML.

In this case tag <abcd></abcd> is missing from the Destination XML. But when I tried to import this specific node to the Destination node result is Merged XML which is not as per my expectation. Expected needs to be identical to Source XML.

Source XML

    <Adapter>
        <Module id="BL">
            <gl>Y</gl>
            <glActivitySeries>AC</glActivitySeries>
            <target>FIC.BL</target>
            <abcd></abcd>
        </Module>
    </Adapter>

Destination XML

        <Adapter>
            <Module id="BL">
                <gl>Y</gl>
                <glActivitySeries>AC</glActivitySeries>
                <target>FIC.BL</target>
            </Module>
        </Adapter>

Merged XML 

            <Adapter>
                <Module id="BL">
                    <gl>Y</gl>
                    <glActivitySeries>AC</glActivitySeries>
                    <target>FIC.BL</target>
                </Module>
                <abcd/>
            </Adapter>

Мой код Java

Получение узла отсутствует в исходном XML

NodeList tempNodeList=node.getElementsByTagName("abcd");
tempNodeList.item(0);

импорт этого узла в целевой XML

Node newTempNode = destDocument.importNode(requiredNode,true);               
destDocument.getDocumentElement().appendChild(newTempNode);

В чем заключается ошибка в моем коде, из-за которой мой вывод не соответствует моим ожиданиям. Любое преимущество будет хорошим.

...