1

Topic: Removal of lines from XML

Is xml ( a config.cfg ):

<setup title = "$ {{ProductTitle}}">
...
<manifest>
<file name = "setup.exe" core = "true"/>
<file name = "setup.cfg"/>
<file name = "eula.txt"/>
<file name = "$ {{EulaHtmlFile}}"/>
<file name = "$ {{FunctionalConsentFile}}"/>
<file name = "$ {{PrivacyPolicyFile}}"/>
<file name = "$ {{InstallerDllDirectory}} /NVI2.dll" core = "true"/>
<file name = "$ {{InstallerDllDirectory}} /NvInstallerUtil.dll" core = "true"/>
<file name = "$ {{InstallerDllDirectory}} /NVI2UI.dll" core = "true"/>
...
</manifest>
</setup>

I need to delete some lines:
<file name = "$ {{EulaHtmlFile}}"/> ,
<file name = "$ {{PrivacyPolicyFile}}"/> ,
<file name = "$ {{InstallerDllDirectory}} /NVI2UI.dll" core = "true"/>
- As it to carry out, looked aside parsing , but it was tangled in a board...
Here an operating time on search of these lines:

var
i: Integer;
s: string;
begin
XMLDocument1.LoadFromFile (' setup.cfg ');
XMLDocument1.Active: = true;
RootNode: = XMLDocument1.DocumentElement;
for i: = 0 to RootNode. ChildNodes [' manifest '].ChildNodes. Count - 1 do
mmo1.Lines. Add (RootNode. ChildNodes [' file '].ChildNodes [i].Text);
//XMLDocument1.ChildNodes. Delete (i); - to it wanted to delete

In  it is deduced nothing...
The moderator: As to me to issue the message?

2

Re: Removal of lines from XML

Use debugging

3

Re: Removal of lines from XML

goldmi45;
It where?

4

Re: Removal of lines from XML

Aqel wrote:

looked aside parsing

What for to you ? If the text of lines at you , without variables???
1: http://docwiki.embarcadero.com/Librarie … eadAllText
2: http://www.delphibasics.ru/StringReplace.php
3: http://docwiki.embarcadero.com/Librarie … iteAllText

5

Re: Removal of lines from XML

goldmi45 wrote:

use debugging

Aqel wrote:

It where?

In ! On !

6

Re: Removal of lines from XML

Parsing it is not necessary, suffices normal TStringList' with removal of the superfluous:

var
sourceList: TStringList;
destList: TStringList;
fileName: string;
I: Integer;
s: string;
begin
fileName: = ' D:\test\install.ini ';
sourceList: = TStringList. Create;
destList: = TStringList. Create;
try
sourceList. LoadFromFile (fileName);
for I: = 0 to sourceList. Count - 1 do
begin
s: = sourceList [i];
if (s = ' <file name = "$ {{EulaHtmlFile}}"/> ')
or (s = ' <file name = "$ {{PrivacyPolicyFile}}"/> ')
or (s = ' <file name = "$ {{InstallerDllDirectory}} /NVI2UI.dll" core = "true"/> ') then
begin
//the pass of unnecessary lines
Continue;
end;
destList. Add (s);
end;
//result we write to the same file
destList. SaveToFile (fileName);
finally
FreeAndNil (sourceList);
FreeAndNil (destList);
end;
end;

7

Re: Removal of lines from XML

JaDi;
Suffices normal string, objects any here are not necessary, especially  string list
Especially you do not process a situation of several tags in single line or gaps to/ambassador

8

Re: Removal of lines from XML

Arioch wrote:

especially you do not process a situation of several tags in single line or gaps to/ambassador

It in  was not :-) Then and gaps in tags it is possible to add, which string replace too cannot process.

9

Re: Removal of lines from XML

Here prompted:

procedure TForm1.Button1Click (Sender: TObject);
const A: array [1. 3] of String = (' EulaHtmlFile ', ' PrivacyPolicyFile ', ' NVI2UI.dll ');
var i, j: integer;
L: TStringList;
begin
L: = TStringList. Create;
L.LoadFromFile (' setup.cfg ');
for i: = L.Count - 1 downto 0 do
for j: = 1 to 3 do
if Pos (A [j], L.Strings [i])> 0 then
begin
L.Delete (i);
break;
end;
L.SaveToFile (' setup.cfg ');
L.Free;
end;

I will add yours try and all a bundle, all thanks!

10

Re: Removal of lines from XML

Aqel;
If the mentioned substrings suddenly meet in any other line except the necessary....
In several different lines of a file for example...
But to you is more visible

11

Re: Removal of lines from XML

Arioch;
There are no there single lines ( which should be deleted ) - repetition is not present. So that to me to approach though and by a simple variant. Though to me still threw  on XML:

uses msxml;//to connect standard for windows XML a parcer
var
doc: IXMLDOMDocument;
list: IXMLDOMNodeList;
xml: IXMLDOMNode;
doc: = CoDOMDocument. Create;
doc. Load (' 1.xml ');//to load the document
r: = doc.selectsingleNode (//file [@name = "$ {{EulaHtmlFile}}"])//we found it that we want to delete
p: = r. ParentNode;//for removal his parent is necessary to us
p. RemoteChild (r);//and now easy we delete
...
doc. Save (....);

file name = "$ {{EulaHtmlFile}}"/>;
To find and delete
To find (further "transfer" of the first code line)
file - - node with a name
//- any enclosure
@name - - with attribute name
= --The having
"$ {{EulaHtmlFile}}" - - preset value
Let's make till three lines for each of the deleted
OR procedure from three lines with parameter a line for removal
+ On code line on each removal
And then to save.

12

Re: Removal of lines from XML

Aqel wrote:

There are no there single lines ( which should be deleted ) - repetition is not present

Then most simple - three commands and one variable