Please note, SOAPHeader is extends Node and Element interfaces:
Document docToAppend= getDoc();
final SOAPHeader soapHeader = getSoapHeader();
final Node importNode = soapHeader.getOwnerDocument().importNode(docToAppend.cloneNode(true), true);
soapHeader.appendChild(importNode);
i.e. i want to append docToAppend
to soapHeader
node.
But it fails with exception:
Caused by: org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation.
I think my code is incorrect.
Package org. w3c. dom Description. Provides the interfaces for the Document Object Model (DOM) which is a component API of the Java API for XML Processing. The Document Object Model Level 2 Core API allows programs to dynamically access and update the content and structure of documents.
The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure. Understanding the DOM is a must for anyone working with HTML or XML.
The XML Document Object Model (DOM) class is an in-memory representation of an XML document. The DOM allows you to programmatically read, manipulate, and modify an XML document. The XmlReader class also reads XML; however, it provides non-cached, forward-only, read-only access.
The XML Document Object Model (DOM) treats XML data as a standard set of objects and is used to process XML data in memory. The System. Xml namespace provides a programmatic representation of XML documents, fragments, nodes, or node-sets.
Had the same error NOT_SUPPORTED_ERR.
DOMResult dom = new DOMResult();
getTransformer().transform(new StAXSource(xmlr), dom);
Node node = dom.getNode();
document.appendChild(document.importNode(node, true)); // <---- Error
Found that trying to add document instead of element by checking the type of the node.
System.out.println("Node type is [" + dom.getNode().getNodeType() + "]");
----
Node type is [9] <---- DOCUMENT_NODE
Get the first child of the document node.
node = dom.getNode().getFirstChild();
System.out.println("Node type is [" + node.getNodeType() + "]");
document.appendChild(document.importNode(node, true));
----
Node type is 1 <---- ELEMENT_NODE
DOCUMENT_NODE and ELEMENT_NODE values are specified in JAVA API Constant Field Values.
SOAPHeader object can have only SOAPHeaderElement objects as its immediate children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With