I created an XML document using Java in my android application. I have to call a web service in my application and pass this XML as an argument there. But my problem is ther
You can create a copy of all nodes in a document, and trims the nodeValue of each node if it exists.
const copyChildrenNodesWithoutWhiteSpace = (document) => {
const clone = document.cloneNode();
for (const child of document.childNodes) {
const childCopy = copyChildrenNodesWithoutWhiteSpace(child);
clone.appendChild(childCopy);
if (childCopy.nodeValue) {
childCopy.nodeValue = childCopy.nodeValue.trim();
}
}
return clone;
};
const result = copyChildrenNodesWithoutWhiteSpace(anyDocument);