Reputation: 99
Is there a way to remove an attribute from an element? I know an attribute can be replaced as shown below.
var node = new NodeBuilder();
node.addAttribute("myAttribute", "attributeValue");
xdmp.nodeReplace(attributeElement.getAttributeNode("myAttribute"),node.toNode());
But I want to completely remove the attribute from an element.
Upvotes: 1
Views: 447
Reputation: 20414
You are probably looking for xdmp.nodeDelete.
It may sound a bit strange, but it also works on attributes:
declareUpdate();
xdmp.documentInsert("/test.xml", xdmp.unquote('<test a="x" b="y">text</test>'));
followed by:
declareUpdate();
xdmp.nodeDelete(cts.doc("/test.xml").xpath("/test/@a"))
Keep in mind though, these functions only work on nodes persisted in the database.
HTH!
Upvotes: 3