I ask the help by JclSimpleXml
Have such a the file
<?
xml version="1.0" encoding="windows-1251" standalone="no"?>
<library>
<section name="textbooks">
<IDX description="author1" appkey="book"/>
</section>
<section name="handbooks">
<IDX description="author1" appkey="book"/>
<IDX description="author2" appkey="book"/>
<IDX description="author3" appkey="book"/>
</section>
</library>
Necessary add and delete "Section" and "IDX" elements
My attempt to add elements
Delphi-Quellcode:
procedure TForm1.SaveClick(Sender: TObject);
const
MyXML = '
C:\MyFile\Book.xml';
var
XML: TJclSimpleXML;
Root: TJclSimpleXMLElem;
I: Integer;
Section, DecStr:
string;
Str: TStringList;
begin
DecStr := combobox1.Text;
// Section selected of combobox
if FileExists(MyXML)
then
begin
XML := TJclSimpleXML.Create;
Str := TStringList.Create;
try
XML.LoadFromFile(MyXML);
XML.Root.
Name := '
library';
Root :=
XML.Root;
for I := 0
to XML.Root.ItemCount - 1
do
begin
Section := Root.Items.Item[I].Properties.Value('
name');
if SameText(Section, DecStr) = True
then
begin
begin
with XML.Root.Items.Item[I].Items.Insert('
IDX', combobox1.ItemIndex)
do
begin
Properties.Add('
author', edit1.Text);
Properties.Add('
book', EntityEncode(edit2.Text));
end;
end;
end;
end;
DecStr := XMLDecode(
XML.SaveToString);
Str.Add(DecStr);
Str.SaveToFile(MyXML , TEncoding.
Default);
finally
XML.Free;
FreeAndNil(Str);
end;
end;
end;
I can not insert them to end of Section
How to implement the insertion and removal "Section" and "IDX"
vereinbart aber Probleme bei der Decodierung EntityEncode