📄 omnixmlproperties.pas
字号:
raise Exception.Create('TGpXMLData.GetAsString: OwnerList is not set')
else begin
xmlStandalone := xmlList.CreateStandalone;
try
xmlStandalone.Assign(Self);
Result := xmlStandalone.AsString;
finally FreeAndNil(xmlStandalone); end;
end;
end; { TGpXMLData.GetAsString }
function TGpXMLData.GetText: string;
begin
Result := Node.Text;
end; { TGpXMLData.GetText }
function TGpXMLData.GetXMLAttrProp(index: integer): string;
begin
Result := GetNodeAttrStr(xmlNode, xmlChildNodeTags[index],
WideString(xmlChildNodeDefaults[index]));
end; { TGpXMLData.GetXMLAttrProp }
function TGpXMLData.GetXMLAttrPropBool(index: integer): boolean;
begin
Result := GetNodeAttrBool(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropBool }
function TGpXMLData.GetXMLAttrPropCardinal(index: integer): cardinal;
begin
Result := cardinal(GetXMLAttrPropInt64(index));
end; { TGpXMLData.GetXMLAttrPropCardinal }
function TGpXMLData.GetXMLAttrPropDate(index: integer): TDateTime;
begin
Result := GetNodeAttrDate(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropDate }
function TGpXMLData.GetXMLAttrPropDateTime(index: integer): TDateTime;
begin
Result := GetNodeAttrDateTime(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropDateTime }
function TGpXMLData.GetXMLAttrPropDWORD(index: integer): DWORD;
begin
Result := DWORD(GetXMLAttrPropInt(index));
end; { TGpXMLData.GetXMLAttrPropDWORD }
function TGpXMLData.GetXMLAttrPropInt(index: integer): integer;
begin
Result := GetNodeAttrInt(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropInt }
function TGpXMLData.GetXMLAttrPropInt64(index: integer): int64;
begin
Result := GetNodeAttrInt64(xmlNode, xmlChildNodeTags[index],
StrToIntDef(xmlChildNodeDefaults[index], 0));
end; { TGpXMLData.GetXMLAttrPropInt64 }
function TGpXMLData.GetXMLAttrPropReal(index: integer): real;
begin
Result := GetNodeAttrReal(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropReal }
function TGpXMLData.GetXMLAttrPropTime(index: integer): TDateTime;
begin
Result := GetNodeAttrTime(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLAttrPropTime }
function TGpXMLData.GetXMLProp(index: integer): string;
begin
Result := GetNodeTextStr(xmlNode, xmlChildNodeTags[index],
WideString(xmlChildNodeDefaults[index]));
end; { TGpXMLData.GetXMLProp }
function TGpXMLData.GetXMLPropBool(index: integer): boolean;
begin
Result := GetNodeTextBool(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropBool }
function TGpXMLData.GetXMLPropCardinal(index: integer): cardinal;
begin
Result := cardinal(GetXMLPropInt64(index));
end; { TGpXMLData.GetXMLPropCardinal }
function TGpXMLData.GetXMLPropCData(index: integer): string;
begin
Result := GetNodeCData(xmlNode, xmlChildNodeTags[index],
WideString(xmlChildNodeDefaults[index]));
end; { TGpXMLData.GetXMLPropCData }
function TGpXMLData.GetXMLPropDate(index: integer): TDateTime;
begin
Result := GetNodeTextDate(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropDate }
function TGpXMLData.GetXMLPropDateTime(index: integer): TDateTime;
begin
Result := GetNodeTextDateTime(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropDateTime }
function TGpXMLData.GetXMLPropDWORD(index: integer): DWORD;
begin
Result := DWORD(GetXMLPropInt(index));
end; { TGpXMLData.GetXMLPropDWORD }
function TGpXMLData.GetXMLPropInt(index: integer): integer;
begin
Result := GetNodeTextInt(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropInt }
function TGpXMLData.GetXMLPropInt64(index: integer): int64;
begin
Result := GetNodeTextInt64(xmlNode, xmlChildNodeTags[index],
StrToIntDef(xmlChildNodeDefaults[index], 0));
end; { TGpXMLData.GetXMLPropInt64 }
function TGpXMLData.GetXMLPropReal(index: integer): real;
begin
Result := GetNodeTextReal(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropReal }
function TGpXMLData.GetXMLPropTime(index: integer): TDateTime;
begin
Result := GetNodeTextTime(xmlNode, xmlChildNodeTags[index],
xmlChildNodeDefaults[index]);
end; { TGpXMLData.GetXMLPropTime }
{:Init 'tags' and 'defaults' arrays.
@since 2003-01-13
}
procedure TGpXMLData.InitChildNodes(tags: array of string;
defaults: array of Variant);
var
iNode: integer;
begin
if Length(tags) <> Length(defaults) then
raise Exception.Create('TGpXMLData.InitChildNodes: Size of ''tags'' and ''defaults'' arrays doesn''t match');
SetLength(xmlChildNodeTags, Length(tags));
SetLength(xmlChildNodeDefaults, Length(tags));
for iNode := 0 to Length(tags)-1 do begin
xmlChildNodeTags[iNode] := tags[iNode];
xmlChildNodeDefaults[iNode] := defaults[iNode];
end; //for
end; { TGpXMLData.InitChildNodes }
{:Set contents of an object.
@since 2002-12-25
}
procedure TGpXMLData.SetAsString(const Value: string);
var
xmlStandalone: TGpXMLData;
begin
if assigned(xmlXMLDoc) then begin
XMLLoadFromString(xmlXMLDoc, '<standalone>'+Value+'</standalone>');
xmlNode := xmlXMLDoc.DocumentElement;
end
else if not assigned(xmlList) then
raise Exception.Create('TGpXMLData.SetAsString: OwnerList is not set')
else begin
xmlStandalone := xmlList.CreateStandalone;
try
xmlStandalone.AsString := Value;
Assign(xmlStandalone);
finally FreeAndNil(xmlStandalone); end;
end;
end; { TGpXMLData.SetAsString }
procedure TGpXMLData.SetText(const Value: string);
begin
xmlNode.Text := Value;
end; { TGpXMLData.SetText }
procedure TGpXMLData.SetXMLAttrProp(const index: integer;
const value: string);
begin
SetNodeAttrStr(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrProp }
procedure TGpXMLData.SetXMLAttrPropBool(const index: integer;
const value: boolean);
begin
SetNodeAttrBool(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropBool }
procedure TGpXMLData.SetXMLAttrPropCardinal(const index: integer;
const value: cardinal);
begin
SetXMLAttrPropInt64(index, value);
end; { TGpXMLData.SetXMLAttrPropCardinal }
procedure TGpXMLData.SetXMLAttrPropDate(const index: integer;
const value: TDateTime);
begin
SetNodeAttrDate(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropDate }
procedure TGpXMLData.SetXMLAttrPropDateTime(const index: integer;
const value: TDateTime);
begin
SetNodeAttrDateTime(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropDateTime }
procedure TGpXMLData.SetXMLAttrPropDWORD(const index: integer;
const value: DWORD);
begin
SetXMLAttrPropInt(index, integer(value));
end; { TGpXMLData.SetXMLAttrPropDWORD }
procedure TGpXMLData.SetXMLAttrPropInt(const index, value: integer);
begin
SetNodeAttrInt(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropInt }
procedure TGpXMLData.SetXMLAttrPropInt64(const index: integer;
const value: int64);
begin
SetNodeAttrInt64(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropInt64 }
procedure TGpXMLData.SetXMLAttrPropReal(const index: integer;
const value: real);
begin
SetNodeAttrReal(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropReal }
procedure TGpXMLData.SetXMLAttrPropTime(const index: integer;
const value: TDateTime);
begin
SetNodeAttrTime(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLAttrPropTime }
procedure TGpXMLData.SetXMLProp(const index: integer; const value: string);
begin
SetNodeTextStr(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLProp }
procedure TGpXMLData.SetXMLPropBool(const index: integer;
const value: boolean);
begin
SetNodeTextBool(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropBool }
procedure TGpXMLData.SetXMLPropCardinal(const index: integer;
const value: cardinal);
begin
SetXMLPropInt64(index, value);
end; { TGpXMLData.SetXMLPropCardinal }
procedure TGpXMLData.SetXMLPropCData(const index: integer;
const value: string);
begin
SetNodeCData(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropCData }
procedure TGpXMLData.SetXMLPropDate(const index: integer;
const value: TDateTime);
begin
SetNodeTextDate(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropDate }
procedure TGpXMLData.SetXMLPropDateTime(const index: integer;
const value: TDateTime);
begin
SetNodeTextDateTime(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropDateTime }
procedure TGpXMLData.SetXMLPropDWORD(const index: integer;
const value: DWORD);
begin
SetXMLPropInt(index, integer(value));
end; { TGpXMLData.SetXMLPropDWORD }
procedure TGpXMLData.SetXMLPropInt(const index, value: integer);
begin
SetNodeTextInt(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropInt }
procedure TGpXMLData.SetXMLPropInt64(const index: integer;
const value: int64);
begin
SetNodeTextInt64(xmlNode, xmlChildNodeTags[index], value);
end; { TGpXMLData.SetXMLPropInt64 }
procedure TGpXMLData.SetXMLPropReal(const index: integer;
const value: real);
begin
SetNodeTextReal(xmlNode,xmlChildNodeTags[index],value);
end; { TGpXMLData.SetXMLPropReal }
procedure TGpXMLData.SetXMLPropTime(const index: integer;
const value: TDateTime);
begin
SetNodeTextTime(xmlNode,xmlChildNodeTags[index],value);
end; { TGpXMLData.SetXMLPropTime }
{ TGpXMLVolatileData }
constructor TGpXMLVolatileData.Create(node: IXMLNode);
begin
inherited Create(node);
MarkVolatile;
end; { TGpXMLVolatileData.Create }
constructor TGpXMLVolatileData.Create;
begin
inherited Create;
MarkVolatile;
end; { TGpXMLVolatileData.Create }
{:Mark XML node as volatile.
@since 2003-01-06
}
procedure TGpXMLVolatileData.MarkVolatile;
begin
SetNodeAttrBool(xmlNode, CIsVolatileAttr, true);
SetNodeAttrBool(xmlNode.OwnerDocument.DocumentElement, CContainsVolatileAttr, true);
end; { TGpXMLVolatileData.MarkVolatile }
{ TGpXMLPrivateData }
constructor TGpXMLPrivateData.Create(node: IXMLNode);
begin
inherited Create(node);
MarkPrivate;
end; { TGpXMLPrivateData.Create }
constructor TGpXMLPrivateData.Create;
begin
inherited Create(node);
MarkPrivate;
end; { TGpXMLPrivateData.Create }
procedure TGpXMLPrivateData.MarkPrivate;
begin
SetNodeAttrBool(xmlNode, CIsPrivateAttr, true);
SetNodeAttrBool(xmlNode.OwnerDocument.DocumentElement, CContainsPrivateAttr, true);
end; { TGpXMLPrivateData.MarkPrivate }
{ TGpXMLList }
{:Create new child node and add it to the list.
@returns New child node.
}
function TGpXMLList.Add: TGpXMLData;
var
newNode: IXMLNode;
begin
Assert(assigned(Node),'Node is not assigned in TGpXMLList.Add');
newNode := xmlNode.OwnerDocument.CreateElement(xmlChildTag);
Assert(assigned(newNode),'Child node is not assigned in TGpXMLList.Add');
xmlNode.AppendChild(newNode);
Result := xmlChildClass.Create(newNode);
Result.OwnerList := Self;
xmlChildNodes.Add(Result);
end; { TGpXMLList.Add }
{:Clear the node list.
}
procedure TGpXMLList.Clear;
begin
xmlChildNodes.Clear;
DeleteAllChildren(xmlNode);
end; { TGpXMLList.Clear }
{:Get number of nodes in the list.
@returns Number of nodes in the list.
}
function TGpXMLList.Count: integer;
begin
Result := xmlChildNodes.Count;
end; { TGpXMLList.Count }
{:Create list of equally named nodes.
@param parentNode Parent XML node.
@param nodeTag Tag of the node containing child nodes.
@param childTag Child nodes' tag.
@param childClass Class of the child nodes.
}
constructor TGpXMLList.Create(parentNode: IXMLNode; nodeTag, childTag: string;
childClass: TGpXMLDataClass);
var
childNode: TGpXMLData;
csList : IXMLNodeList;
csNode : IXMLNode;
begin
Assert(assigned(parentNode), 'Parent node is not assigned in TGpXMLList.Create');
if nodeTag = '' then
xmlNode := parentNode
else begin
xmlNode := parentNode.SelectSingleNode(nodeTag);
if not assigned(xmlNode) then begin
xmlNode := parentNode.OwnerDocument.CreateElement(nodeTag);
parentNode.AppendChild(xmlNode);
end;
end;
xmlChildClass := childClass;
xmlChildTag := childTag;
xmlChildNodes := TObjectList.Create(true);
csList := xmlNode.SelectNodes(childTag);
csList.Reset;
repeat
csNode := csList.NextNode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -