I have the following XML:
<TABLE Table="STUDENT">
<FIELD fieldName="ID" fldType="INT"/>
<FIELD fieldName="NAME" fldType="STRING"/>
<FIELD fieldName="REDUNDANTFIELD" fldType="STRING"/>
<FIELD fieldName="PHONENUMBER" fldType="STRING"/>
</TABLE>
I want to remove the row where the attribute of the fieldname is "REDUNDANTFIELD" .. How can i do it ?
Expected output after the row is deleted
<TABLE Table="STUDENT">
<FIELD fieldName="ID" fldType="INT"/>
<FIELD fieldName="NAME" fldType="STRING"/>
<FIELD fieldName="PHONENUMBER" fldType="STRING"/>
</TABLE>
Can anyone help me to proceed with the following function ?
function RemoveAttributeRRow(myXML: IXMLDOMDocument2): IXMLDOMDocument2;
begin
// my code here
Result:= ???;
end;
procedure RemoveAttributeRRow(doc: IXMLDOMDocument2);
var
node: IXMLDOMNode;
begin
node := Doc.selectSingleNode('//FIELD[@fieldName=''REDUNDANTFIELD'']');
if node<>nil then
node.parentNode.removeChild(node);
end;
procedure TForm14.Button3Click(Sender: TObject);
var
m: IXMLDOMDocument2;
begin
m := CoDOMDocument.Create;
m.load('c:\work\1.xml');
RemoveAttributeRRow(m);
m.save('c:\work\2.xml');
end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.