开发者

How to delete a child node using OmniXML?

I'd like to delete the line with pathid="2" in the rowpath section...

<?xml version="1.0" encoding="utf-8"?>
<LostPath Condition="Active" Selected="train.exe" FullPathOfSelected="D:\mygames\arcade\train\" Selected="0">
  <rowdir Name="train.exe" GamePath="D:\mygames\arcade\train\" Selected="0" />
  <rowdir Name="othelo.exe" GamePath="D:\mygames\arcade\othello\" Selected="3"/>
  <rowpath Name="train.exe" PathId="1" LevelPath="D:\mygames\arcade\train\levelpack1" levelsFound="27" />
  <rowpath Name="train.exe" PathId="2" LevelPath="D:\mygames\arcade\train\levelpack21" levelsFound="19" />
  <rowpath Name="othelo.exe" PathId="0"开发者_开发问答 LevelPath="D:\mygames\arcade\othelo\levelpack1" levelsFound="11" />
</LostPath>

How can I do that ?


Try to use this.

uses
  OmniXML, OmniXMLUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  XMLNode: IXMLNode;
  XMLDocument: IXMLDocument;
begin
  XMLDocument := CreateXMLDoc;
  if XMLLoadFromFile(XMLDocument, 'XMLFile.xml') then
  begin
    XMLNode := XMLDocument.SelectSingleNode('/LostPath');
    DeleteNode(XMLNode, 'rowpath[@PathId="2"]');
    XMLDocument.Save('XMLFile.xml');
  end;
end;


There are few ways how to delete all nodes with the same attribute value. Here's one of them. But please note, this post doesn't answer this question. It should be asked as another question.

uses
  OmniXML, OmniXMLUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  XMLNode: IXMLNode;
  XMLDocument: IXMLDocument;
begin
  XMLDocument := CreateXMLDoc;
  if XMLLoadFromFile(XMLDocument, 'XMLFile.xml') then
  begin
    XMLNode := XMLDocument.SelectSingleNode('/LostPath');
    DeleteAllChildren(XMLNode, 'rowpath[@Name="train.exe"]');
    XMLDocument.Save('XMLFile.xml');
  end;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜