-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuXMLUtils.pas
More file actions
74 lines (58 loc) · 1.66 KB
/
uXMLUtils.pas
File metadata and controls
74 lines (58 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
unit uXMLUtils;
interface
uses
XMLDoc, XmlIntf;
type
TXMLUtils = class
private
FXML: IXMLDocument;
FRootNode: IXMLNode;
public
property XML: IXMLDocument read FXML write FXML;
constructor Create(rootName: string);
function AddElement(ElemName: string; ElemValue: string = ''): IXMLNode; overload;
function AddElement(ParentNode: IXMLNode; ElemName, ElemValue: string): IXMLNode; overload;
function AddNode(NodeName: string): IXMLNode;
function AddAttribute(Node: IXMLNode; AttrName: string; AttrValue: string = ''): IXMLNode;
function XMLText(Formatted: Boolean = False): string;
end;
const
cFormattedXML = True;
implementation
{ TXMLUtils }
constructor TXMLUtils.Create(rootName: string);
var
node: IXMLNode;
begin
FXML := NewXMLDocument;
FRootNode := FXML.AddChild(rootName);
end;
function TXMLUtils.XMLText(Formatted: Boolean = False) : string;
begin
Result := FXML.XML.Text;
if Formatted then
Result := FormatXMLData(Result);
end;
function TXMLUtils.AddElement(ElemName: string; ElemValue: string = ''): IXMLNode;
var
node: IXMLNode;
begin
Result := FRootNode.AddChild(ElemName);
if ElemValue <> '' then
Result.NodeValue := ElemValue;
end;
function TXMLUtils.AddElement(ParentNode: IXMLNode; ElemName, ElemValue: string): IXMLNode;
begin
Result := ParentNode.AddChild(ElemName);
Result.NodeValue := ElemValue;
end;
function TXMLUtils.AddNode(NodeName: string): IXMLNode;
begin
Result := FXML.CreateElement(NodeName, '');
end;
function TXMLUtils.AddAttribute(Node: IXMLNode; AttrName: string; AttrValue: string = ''): IXMLNode;
begin
Node.Attributes[AttrName] := AttrValue;
Result := Node;
end;
end.