mirror of
https://github.com/Kirill/simplexml.git
synced 2024-11-21 13:15:48 +02:00
Version 1.0.1
This commit is contained in:
parent
51b4067d1b
commit
bef25364bc
13
Sample/Test.dpr
Normal file
13
Sample/Test.dpr
Normal file
@ -0,0 +1,13 @@
|
||||
program Test;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
TestForms in 'TestForms.pas' {TestForm};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TTestForm, TestForm);
|
||||
Application.Run;
|
||||
end.
|
BIN
Sample/Test.res
Normal file
BIN
Sample/Test.res
Normal file
Binary file not shown.
6
Sample/Test.xml
Normal file
6
Sample/Test.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<root>
|
||||
<elem1 a1="v1" a2="v2"> 1</elem1>
|
||||
<!-- -->
|
||||
<elem2 a1="v1" a2="v2"> 2</elem2>
|
||||
</root>
|
43
Sample/TestForms.dfm
Normal file
43
Sample/TestForms.dfm
Normal file
@ -0,0 +1,43 @@
|
||||
object TestForm: TTestForm
|
||||
Left = 267
|
||||
Top = 132
|
||||
Width = 696
|
||||
Height = 480
|
||||
Caption = 'TestForm'
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -13
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
PixelsPerInch = 120
|
||||
TextHeight = 16
|
||||
object Button1: TButton
|
||||
Left = 40
|
||||
Top = 16
|
||||
Width = 75
|
||||
Height = 25
|
||||
Caption = 'Open'
|
||||
TabOrder = 0
|
||||
OnClick = Button1Click
|
||||
end
|
||||
object Memo1: TMemo
|
||||
Left = 40
|
||||
Top = 60
|
||||
Width = 361
|
||||
Height = 309
|
||||
Lines.Strings = (
|
||||
'Memo1')
|
||||
TabOrder = 1
|
||||
end
|
||||
object Button2: TButton
|
||||
Left = 128
|
||||
Top = 16
|
||||
Width = 75
|
||||
Height = 25
|
||||
Caption = 'Save'
|
||||
TabOrder = 2
|
||||
OnClick = Button2Click
|
||||
end
|
||||
end
|
81
Sample/TestForms.pas
Normal file
81
Sample/TestForms.pas
Normal file
@ -0,0 +1,81 @@
|
||||
unit TestForms;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, SimpleXML, StdCtrls;
|
||||
|
||||
type
|
||||
TTestForm = class(TForm)
|
||||
Button1: TButton;
|
||||
Memo1: TMemo;
|
||||
Button2: TButton;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
TestForm: TTestForm;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TTestForm.Button1Click(Sender: TObject);
|
||||
var
|
||||
aDoc: IXmlDocument;
|
||||
anElem2: IXmlNode;
|
||||
begin
|
||||
// Ñîçäàåì ïóñòîé äîêóìåíò XML
|
||||
aDoc := CreateXmlDocument;
|
||||
|
||||
// Ñ÷èòûâàåì èç ôàéëà
|
||||
aDoc.Load(ExtractFilePath(ParamStr(0)) + '\Test.xml');
|
||||
|
||||
// Âûâîäèì â Memo1 ïîëíûé òåêñò ñ÷èòàíîãî XML
|
||||
Memo1.Lines.Text := aDoc.Xml;
|
||||
|
||||
Memo1.Lines.Add('------------------------');
|
||||
|
||||
// Èùåì ïåðâûé ýëåìåíò ñ òýãîì 'elem2'
|
||||
anElem2 := aDoc.DocumentElement.SelectSingleNode('elem2');
|
||||
|
||||
// Âûâîäèì â Memo1 XML-òåêñò ýëåìåíòà anElem2
|
||||
Memo1.Lines.Add(anElem2.Xml);
|
||||
|
||||
Memo1.Lines.Add('------------------------');
|
||||
|
||||
// Âûâîäèì â Memo1 çíà÷åíèå àòðèáóòà 'a2' ýëåìåíòà anElem2
|
||||
Memo1.Lines.Add(anElem2.GetAttr('a2'));
|
||||
end;
|
||||
|
||||
procedure TTestForm.Button2Click(Sender: TObject);
|
||||
var
|
||||
aDoc: IXmlDocument;
|
||||
anElem: IXmlElement;
|
||||
begin
|
||||
// Ñîçäàåì ïóñòîé äîêóìåíò XML ñ êîðíåâûì ýëåìåíòîì "root-element"
|
||||
aDoc := CreateXmlDocument('xml');
|
||||
|
||||
// Ñîçäàåì ýëåìåíò 'elem' è äîáàâëÿåì åãî â êà÷åñòâå äî÷åðíåãî ýëåìåíòà äëÿ êîðíåâîãî
|
||||
anElem := aDoc.DocumentElement.AppendElement('elem');
|
||||
|
||||
// Äîáàâëÿåì àòðèáóòû 'a1' è 'a2' ê íîâîìó ýëåìåíòó
|
||||
anElem.SetAttr('a1', 'elem1 a1');
|
||||
anElem.SetAttr('a2', 'elem1 a2');
|
||||
|
||||
// Äîáàâëÿåì åùå îäèí ýëåìåíò 'elem'
|
||||
anElem := aDoc.DocumentElement.AppendElement('elem');
|
||||
anElem.SetAttr('a1', 'elem2 a1');
|
||||
anElem.SetAttr('a2', 'elem2 a2');
|
||||
|
||||
// Ñîõðàíÿåì äîêóìåíò â ôàéë
|
||||
aDoc.Save(ExtractFilePath(ParamStr(0)) + '\Test2.xml');
|
||||
end;
|
||||
|
||||
end.
|
BIN
SimpleXML.chm
Normal file
BIN
SimpleXML.chm
Normal file
Binary file not shown.
4479
SimpleXML.pas
Normal file
4479
SimpleXML.pas
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user