我有以下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>
我想删除fieldname属性为“REDUNDANTFIELD”的行。我该怎么办?
删除行后的预期输出
<TABLE Table="STUDENT">
<FIELD fieldName="ID" fldType="INT"/>
<FIELD fieldName="NAME" fldType="STRING"/>
<FIELD fieldName="PHONENUMBER" fldType="STRING"/>
</TABLE>
任何人都可以帮我继续以下功能吗?
function RemoveAttributeRRow(myXML: IXMLDOMDocument2): IXMLDOMDocument2;
begin
// my code here
Result:= ???;
end;
答案 0 :(得分:1)
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;