2

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 ?

TLama
  • 75,147
  • 17
  • 214
  • 392
azrael11
  • 417
  • 6
  • 18

2 Answers2

4

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;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • Thank you my friend works fine.. I have one more question. If i want to erase all the node of rowpath with name="train" how can i do that.. – azrael11 Sep 30 '11 at 01:34
2

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;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • When i do this i get a "XMLEnumNodes undeclered identifier" but i hhave the OmniXMLUtils in my uses... i have delphi 7 i think that the for...in doen't work in delphi 7 am i right? – azrael11 Oct 01 '11 at 03:27
  • @azrael11, yeah, you're right. Sorry, I missed that Delphi 7 tag. I'll update the answer, but also delete it later on, because this should be asked separately for future users who will look for this specific question. – TLama Oct 01 '11 at 10:44
  • When i do this i get an error that "Invalid syntax at position 52" i don't understand... – azrael11 Oct 04 '11 at 03:24
  • @azrael11, please post it as another question to help someone who will have the same problem in the future. In the meantime check if you have correct number of `[]` brackets because this error is thrown only when you have something wrong with these brackets in your expression. – TLama Oct 04 '11 at 05:52
  • Please i am new here what i must do... is that i am thinging is OK 1. make a new question and 2.how can i copy paste your anwser... sorry as i say i am new here.... – azrael11 Oct 04 '11 at 10:04
  • @azrael11, no problem. If you add the new question "how to delete all nodes with the same attribute value" and you have a problem with it, describe it with all details we need to know (error message you're getting and the code you are using). You can also answer and accept your answer so feel free to do it by your own. – TLama Oct 04 '11 at 10:34