我用的是delphi里的IXMLDOCUMENT控件,在写XML文件时程序自动把XML中的所有单引号更改为双引号,还有程序每输入一个子结点不能自动换行。请各位高手不吝赐教,这两个问题该如何解决啊。小弟先行感谢了!
解决方案 »
- 现在delphi2006中用fastreport的都在用什么版本的?有个免费下载链接就更好了,谢谢先!~
- 找人开发一个简单的图像处理软件,有薪酬~~~
- 关于DES加密算法的秘匙长度问题,100分!!!
- 怎样实现QQ或MSN发送消息窗口的多重创建?
- 如何将6个edit中的数据排序后,在他们的下面对应显示IMAGE格式的第一....第六的图图片???
- 郁闷,能不能给出具体的代码
- BDE的使用和MS SQLSERVER2000的安装
- delphi使用汇编问题
- query1.requestlive=true/false问题?
- 如何避免ListView添加项目时的闪烁
- 请高手们指点一下(急用)
- 按键播放MP3文件
http://www.delphibox.com/article.asp?articleid=2654
http://www.delphifans.com/SoftView/SoftView_1295.html
楼主参考使用,没问题//==============================================================================
// Function: 扩充TXMLDocument的操作便利性
//==============================================================================
unit UXMLDocument;interfaceuses
XMLIntf, XMLDoc;type
TMyXMLDocument = class(TXMLDocument)
public
function GetNodeValue(NodeName: array of WideString;
const DefValue: OleVariant): OleVariant;
procedure SetNodeValue(NodeName: array of WideString;
const Value: OleVariant);
end;implementation{ TMyXMLDocument }function TMyXMLDocument.GetNodeValue(NodeName: array of WideString;
const DefValue: OleVariant): OleVariant;
//==============================================================================
// Function: 获得节点值,如果节点不存在,则返回默认值DefValue
//Parameters: NodeName表示多级节点名称,DefValue表示如果节点不存在的返回值
// Result: 节点内容
//==============================================================================
var
I: Integer;
Root: IXMLNode;
begin
Result := DefValue;
if DocumentElement = nil then Exit;
Root := DocumentElement;
for I := 0 to Length(NodeName) -1 do
begin
if Root = nil then Break;
Root := Root.ChildNodes.FindNode(NodeName[I]);
end;
if Root <> nil then
Result := Root.NodeValue;
end;procedure TMyXMLDocument.SetNodeValue(NodeName: array of WideString;
const Value: OleVariant);
//==============================================================================
// Function: 设置节点内容,如果节点不存在,则创建节点;如果根节点不存在,则不进
// 行任何操作
//Parameters: NodeName表示多级节点名称,Value表示节点值
//==============================================================================
var
I: Integer;
Root, Root2: IXMLNode;
begin
if DocumentElement = nil then Exit;
Root := DocumentElement;
for I := 0 to Length(NodeName) -1 do
begin
Root2 := Root.ChildNodes.FindNode(NodeName[I]);
if Root2 = nil then
Root2 := Root.AddChild(NodeName[I]);
Root := Root2;
end;
Root.NodeValue := Value;
end;end.测试单元
--------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, XMLIntf, ComCtrls,
UXMLDocument;type
TfrmMain = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
frmMain: TfrmMain;
const
SettingFileName = 'setting.xml';implementation
{$R *.dfm}procedure TfrmMain.FormCreate(Sender: TObject);
var
XML: TMyXMLDocument;
begin
XML := TMyXMLDocument.Create(Application);
XML.Options := [doNodeAutoCreate, doNodeAutoIndent, doAttrNull, doAutoPrefix, doNamespaceDecl];
try
if FileExists(SettingFileName) then
XML.LoadFromFile(SettingFileName)
else
begin
XML.Active := True;
XML.Create(SettingFileName);
XML.AddChild('Setting', '1.0');
XML.SaveToFile(SettingFileName);
end;
Width := XML.GetNodeValue([Name, 'Width'], Width);
Height := XML.GetNodeValue([Name, 'Height'], Height);
Top := XML.GetNodeValue([Name, 'Top'], Top);
Left := XML.GetNodeValue([Name, 'Left'], Left);
finally
XML.Free;
end;
end;procedure TfrmMain.FormDestroy(Sender: TObject);
var
XML: TMyXMLDocument;
begin
XML := TMyXMLDocument.Create(Application);
XML.Options := [doNodeAutoCreate, doNodeAutoIndent, doAttrNull, doAutoPrefix, doNamespaceDecl];
try
if FileExists(SettingFileName) then
XML.LoadFromFile(SettingFileName)
else
begin
XML.Active := True;
XML.Create(SettingFileName);
XML.AddChild('Setting', '1.0');
end;
XML.SetNodeValue([Name, 'Width'], Width);
XML.SetNodeValue([Name, 'Height'], Height);
XML.SetNodeValue([Name, 'Top'], Top);
XML.SetNodeValue([Name, 'Left'], Left);
finally
XML.SaveToFile(SettingFileName);
XML.Free;
end;
end;end.
donodeautoindent属性设置true,接点可以自动换行
TReplaceFlags): string;DescriptionStringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. StringReplace assumes that the source string may contain Multibyte characters.S is the source string, whose substrings are changed.OldPattern is the substring to locate and replace with NewPattern.NewPattern is the substring to substitute for occurrences of OldPattern.Flags is a set of flags that govern how StringReplace locates and replaces occurrences of OldPattern. If Flags does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, StringReplace replaces all instances of OldPattern with NewPattern. If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.