You can use the IXMLNodeList.Delete() or IXMLNodeList.Remove() method to remove nodes:
var
Root: IXMLNode;
begin
Root := XMLDocument1.DocumentElement;
Root.ChildNodes.Delete('ElementData');
for I := 0 to Root.ChildNodes.Count-1 do
Root.ChildNodes[I].ChildNodes.Delete('ElementData');
end;
var
Root, Child, Node: IXMLNode;
begin
Root := XMLDocument1.DocumentElement;
Node := Root.ChildNodes.FindNode('ElementData');
if Node <> nil then Root.ChildNodes.Remove(Node);
for I := 0 to Root.ChildNodes.Count-1 do
begin
Child := Root.ChildNodes[I];
Node := Child.ChildNodes.FindNode('ElementData');
if Node <> nil then Child.ChildNodes.Remove(Node);
end;
end;
If you want to remove all ElementData elements regardless of their depth within the document, a recursive procedure can do that:
procedure RemoveElementData(Node: IXMLNode);
var
Root, Child: IXMLNode;
begin
repeat until Node.ChildNodes.Delete('ElementData') = -1;
for I := 0 to Node.ChildNodes.Count-1 do
RemoveElementData(Node.ChildNodes[I]);
end;
end;
begin
RemoveElementData(XMLDocument1.DocumentElement);
end;
ExtensionDatais an element, not an attribute, and in this example it has no attributes of its own, either. It is important to get the terminology correct because elements and attributes are accessed in different ways.