⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omnixmlutils.pas

📁 OmniXML源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
end; { XMLStrToBinary }

{:@since   2003-12-12
}        
function GetNodeCData(parentNode: IXMLNode; nodeTag: string;
  defaultValue: WideString): WideString;
var
  myNode: IXMLNode;
begin
  Result := defaultValue;
  myNode := SelectNode(parentNode, nodeTag);
  if assigned(myNode) then begin
    myNode := GetCDataChild(myNode);
    if assigned(myNode) then
      Result := myNode.Text;
  end;
end; { GetNodeCData }

function GetNodeCData(node: IXMLNode): WideString;
var
  cdataNode: IXMLNode;
begin
  cdataNode := GetCDataChild(node);
  if assigned(cdataNode) then
    Result := cdataNode.Text
  else
    Result := '';
end; { GetNodeCData }

function GetNodeText(parentNode: IXMLNode; nodeTag: string;
  var nodeText: WideString): boolean;
var
  myNode: IXMLNode;
begin
  Result := false;
  myNode := SelectNode(parentNode, nodeTag);
  if assigned(myNode) then begin
    myNode := GetTextChild(myNode);
    if assigned(myNode) then begin
      nodeText := myNode.Text;
      Result := true;
    end;
  end;
end; { GetNodeText }

function GetNodeText(node: IXMLNode): WideString;
var
  textNode: IXMLNode;
begin
  textNode := GetTextChild(node);
  if assigned(textNode) then
    Result := textNode.Text
  else
    Result := '';
end; { GetNodeText }

procedure GetNodesText(parentNode: IXMLNode; nodeTag: string;
  {var} nodesText: TStrings); 
var
  iNode: integer;
  nodes: IXMLNodeList;
begin
  nodesText.Clear;
  nodes := parentNode.SelectNodes(nodeTag);
  for iNode := 0 to nodes.Length-1 do
    nodesText.Add(Trim(nodes.Item[iNode].Text));
end; { GetNodesText }

procedure GetNodesText(parentNode: IXMLNode; nodeTag: string;
  var nodesText: string); 
var
  texts: TStringList;
begin
  texts := TStringList.Create;
  try
    GetNodesText(parentNode, nodeTag, texts);
    nodesText := texts.Text;
  finally FreeAndNil(texts); end;
end; { GetNodesText }

function GetNodeTextStr(parentNode: IXMLNode; nodeTag: string;
  defaultValue: WideString): WideString;
begin
  if not GetNodeText(parentNode, nodeTag, Result) then
    Result := defaultValue
  else
    Result := Trim(Result);
end; { GetNodeTextStr }

function GetNodeTextStr(parentNode: IXMLNode; nodeTag: string): WideString;
begin
  if not GetNodeText(parentNode, nodeTag, Result) then
    raise EOmniXMLUtils.CreateFmt('GetNodeTextStr: No text in the the %s node', [nodeTag]);
end; { GetNodeTextStr }

function GetNodeTextReal(parentNode: IXMLNode; nodeTag: string;
  defaultValue: real): real;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode, nodeTag, nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToRealDef(nodeText, defaultValue);
end; { GetNodeTextReal }

function GetNodeTextReal(parentNode: IXMLNode; nodeTag: string): real;
begin
  Result := XMLStrToReal(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextReal }

function GetNodeTextInt(parentNode: IXMLNode; nodeTag: string;
  defaultValue: integer): integer;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToIntDef(nodeText,defaultValue);
end; { GetNodeTextInt }

function GetNodeTextInt(parentNode: IXMLNode; nodeTag: string): integer;
begin
  Result := XMLStrToInt(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextInt }

function GetNodeTextInt64(parentNode: IXMLNode; nodeTag: string;
  defaultValue: int64): int64;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToInt64Def(nodeText,defaultValue);
end; { GetNodeTextInt64 }

function GetNodeTextInt64(parentNode: IXMLNode; nodeTag: string): int64;
begin
  Result := XMLStrToInt64(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextInt64 }

function GetNodeTextBool(parentNode: IXMLNode; nodeTag: string;
  defaultValue: boolean): boolean;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToBoolDef(nodeText,defaultValue);
end; { GetNodeTextBool }

function GetNodeTextBool(parentNode: IXMLNode; nodeTag: string): boolean;
begin
  Result := XMLStrToBool(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextBool }

function GetNodeTextDateTime(parentNode: IXMLNode; nodeTag: string;
  defaultValue: TDateTime): TDateTime;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToDateTimeDef(nodeText,defaultValue);
end; { GetNodeTextDateTime }

function GetNodeTextDateTime(parentNode: IXMLNode; nodeTag: string): TDateTime;
begin
  Result := XMLStrToDateTime(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextDateTime }

function GetNodeTextDate(parentNode: IXMLNode; nodeTag: string;
  defaultValue: TDateTime): TDateTime;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToDateDef(nodeText,defaultValue);
end; { GetNodeTextDate }

function GetNodeTextDate(parentNode: IXMLNode; nodeTag: string): TDateTime;
begin
  Result := XMLStrToDate(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextDate }

function GetNodeTextTime(parentNode: IXMLNode; nodeTag: string;
  defaultValue: TDateTime): TDateTime;
var
  nodeText: WideString;
begin
  if not GetNodeText(parentNode,nodeTag,nodeText) then
    Result := defaultValue
  else
    Result := XMLStrToTimeDef(nodeText,defaultValue);
end; { GetNodeTextTime }

function GetNodeTextTime(parentNode: IXMLNode; nodeTag: string): TDateTime;
begin
  Result := XMLStrToTime(GetNodeTextStr(parentNode, nodeTag));
end; { GetNodeTextTime }

function GetNodeTextBinary(parentNode: IXMLNode; nodeTag: string;
  value: TStream): boolean;
var
  decoded: TMemoryStream;
begin
  decoded := TMemoryStream.Create;
  try
    Result := XMLStrToBinary(GetNodeTextStr(parentNode, nodeTag, ''), decoded);
    if Result then
      value.CopyFrom(decoded, 0);
  finally FreeAndNil(decoded); end;
end; { GetNodeTextBinary }

function GetNodeTextFont(parentNode: IXMLNode; nodeTag: string; value: TFont): boolean;
var
  fontNode: IXMLNode;
  fStyle  : TFontStyles;
  iStyle  : integer;
begin
  Result := false;
  fontNode := SelectNode(parentNode, nodeTag);
  if assigned(fontNode) then begin
    value.Name := GetNodeTextStr(fontNode, 'Name', value.Name);
    value.Charset := GetNodeAttrInt(fontNode, 'Charset', value.Charset);
    value.Color := GetNodeAttrInt(fontNode, 'Color', value.Color);
    value.Height := GetNodeAttrInt(fontNode, 'Height', value.Height);
    value.Pitch := TFontPitch(GetNodeAttrInt(fontNode, 'Pitch', Ord(value.Pitch)));
    value.Size := GetNodeAttrInt(fontNode, 'Size', value.Size);
    fStyle := value.Style;
    iStyle := 0;
    Move(fStyle, iStyle, SizeOf(TFontStyles));
    iStyle := GetNodeAttrInt(fontNode, 'Style', iStyle);
    Move(iStyle, fStyle, SizeOf(TFontStyles));
    value.Style := fStyle;
    Result := true;
  end;
end; { GetNodeTextFont }

function GetNodeAttr(parentNode: IXMLNode; attrName: string;
  var value: WideString): boolean;
var
  attrNode: IXMLNode;
begin
  if IsDocument(parentNode) and assigned(DocumentElement(parentNode)) then
    parentNode := DocumentElement(parentNode);
  attrNode := parentNode.Attributes.GetNamedItem(attrName);
  if not assigned(attrNode) then
    Result := false
  else begin
    value := attrNode.NodeValue;
    Result := true;
  end;
end; { GetNodeAttr }

function GetNodeAttrStr(parentNode: IXMLNode; attrName: string;
  defaultValue: WideString): WideString;
begin
  if not GetNodeAttr(parentNode, attrName, Result) then
    Result := defaultValue
  else
    Result := Trim(Result);
end; { GetNodeAttrStr }

function GetNodeAttrStr(parentNode: IXMLNode; attrName: string): WideString;
begin
  if not GetNodeAttr(parentNode, attrName, Result) then
    raise EOmniXMLUtils.CreateFmt('GetNodeAttrStr: No attribute %s in the the %s node',
      [attrName, parentNode.NodeName]);
end; { GetNodeAttrStr }

function GetNodeAttrReal(parentNode: IXMLNode; attrName: string;
  defaultValue: real): real;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToRealDef(attrValue,defaultValue);
end; { GetNodeAttrReal }

function GetNodeAttrReal(parentNode: IXMLNode; attrName: string): real;
begin
  Result := XMLStrToReal(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrReal }

function GetNodeAttrInt(parentNode: IXMLNode; attrName: string;
  defaultValue: integer): integer;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToIntDef(attrValue,defaultValue);
end; { GetNodeAttrInt }

function GetNodeAttrInt(parentNode: IXMLNode; attrName: string): integer;
begin
  Result := XMLStrToInt(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrInt }

function GetNodeAttrInt64(parentNode: IXMLNode; attrName: string;
  defaultValue: int64): int64;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToInt64Def(attrValue,defaultValue);
end; { GetNodeAttrInt64 }

function GetNodeAttrInt64(parentNode: IXMLNode; attrName: string): int64;
begin
  Result := XMLStrToInt64(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrInt64 }

function GetNodeAttrBool(parentNode: IXMLNode; attrName: string;
  defaultValue: boolean): boolean;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToBoolDef(attrValue,defaultValue);
end; { GetNodeAttrBool }

function GetNodeAttrBool(parentNode: IXMLNode; attrName: string): boolean;
begin
  Result := XMLStrToBool(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrBool }

function GetNodeAttrDateTime(parentNode: IXMLNode; attrName: string;
  defaultValue: TDateTime): TDateTime;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToDateTimeDef(attrValue,defaultValue);
end; { GetNodeAttrDateTime }

function GetNodeAttrDateTime(parentNode: IXMLNode; attrName: string): TDateTime;
begin
  Result := XMLStrToDateTime(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrDateTime }

function GetNodeAttrDate(parentNode: IXMLNode; attrName: string;
  defaultValue: TDateTime): TDateTime;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToDateDef(attrValue,defaultValue);
end; { GetNodeAttrDate }

function GetNodeAttrDate(parentNode: IXMLNode; attrName: string): TDateTime;
begin
  Result := XMLStrToDate(GetNodeAttrStr(parentNode, attrName));
end; { GetNodeAttrDate }

function GetNodeAttrTime(parentNode: IXMLNode; attrName: string;
  defaultValue: TDateTime): TDateTime;
var
  attrValue: WideString;
begin
  if not GetNodeAttr(parentNode,attrName,attrValue) then
    Result := defaultValue
  else
    Result := XMLStrToTimeDef(attrValue,defaultValue);
end; { GetNodeAttrTime }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -