L
linuxping
Unregistered / Unconfirmed
GUEST, unregistred user!
以下函数实现创建节点,然后把Doc保存到文件.但文件里并没有出现新创建的节点:
procedure TCutedFile.AddCutedFile(ACutedPath,ACutedSavePath,ASavetoPath: string;mc:TMethodChoose);
var
do
c:IDOMDocument;
xmlNode,xmlSubNode:IDOMNode;
xmlAttr:IDOMNode;
begin
FXMLDoc.Active:=True;
do
c:=FXMLDoc.DOMDocument;
xmlNode:=Doc.childNodes.item[1];
//xmlNode='CutWord' node.
xmlNode:=xmlNode.appendChild(Doc.createElement('File'));
// xmlnode= 'File' node.
//ShowMessage(xmlNode.nodeName);
xmlAttr:=Doc.createAttribute('scrpath');
//属性节点(xmlAttr='scrpath' node)
xmlAttr.NodeValue:=ACutedPath;
//
xmlNode.attributes.setNamedItem(xmlAttr);
xmlSubNode:=Doc.createElement('Cuted');
xmlNode:=xmlNode.appendChild(xmlSubNode);
//xmlnode='Cuted' node.
xmlAttr:=Doc.createAttribute('time');
//属性节点
xmlAttr.NodeValue:=DateToStr(Date);
xmlNode.attributes.setNamedItem(xmlAttr);
xmlAttr:=Doc.createAttribute('direction');
//属性节点
xmlAttr.NodeValue:=McValue(mc);
xmlNode.attributes.setNamedItem(xmlAttr);
xmlNode.appendChild(Doc.createTextNode(ACutedSavePath));
//添加文本
FXMLDoc.Active:=False;
FXMLDoc.Active:=True;
//FXMLDoc.Resync;
//ShowMessage(FXMLDoc.XML.Text);
ForceDomTofile(ASavetoPath);
end;
procedure TCutedFile.ForceDomTofile(APath:string);//Dom保存到文件
var
strmMemo:TMemoryStream;
strmString:TStringStream;
sEncry:string;
begin
FXMLDoc.NodeIndentStr:=#32#32;
sEncry:=FSecret.EncryptString(FormatXMLData(FXMLDoc.XML.Text),xmlKEY);//这是个加密函数
strmString:=TStringStream.Create(sEncry);
try
strmMemo:=TMemoryStream.Create;
try
strmMemo.LoadFromStream(strmString);
strmMemo.SaveToFile(APath);
finally
strmMemo.Free;
end;
finally
strmString.Free;
end;
end;
procedure TCutedFile.AddCutedFile(ACutedPath,ACutedSavePath,ASavetoPath: string;mc:TMethodChoose);
var
do
c:IDOMDocument;
xmlNode,xmlSubNode:IDOMNode;
xmlAttr:IDOMNode;
begin
FXMLDoc.Active:=True;
do
c:=FXMLDoc.DOMDocument;
xmlNode:=Doc.childNodes.item[1];
//xmlNode='CutWord' node.
xmlNode:=xmlNode.appendChild(Doc.createElement('File'));
// xmlnode= 'File' node.
//ShowMessage(xmlNode.nodeName);
xmlAttr:=Doc.createAttribute('scrpath');
//属性节点(xmlAttr='scrpath' node)
xmlAttr.NodeValue:=ACutedPath;
//
xmlNode.attributes.setNamedItem(xmlAttr);
xmlSubNode:=Doc.createElement('Cuted');
xmlNode:=xmlNode.appendChild(xmlSubNode);
//xmlnode='Cuted' node.
xmlAttr:=Doc.createAttribute('time');
//属性节点
xmlAttr.NodeValue:=DateToStr(Date);
xmlNode.attributes.setNamedItem(xmlAttr);
xmlAttr:=Doc.createAttribute('direction');
//属性节点
xmlAttr.NodeValue:=McValue(mc);
xmlNode.attributes.setNamedItem(xmlAttr);
xmlNode.appendChild(Doc.createTextNode(ACutedSavePath));
//添加文本
FXMLDoc.Active:=False;
FXMLDoc.Active:=True;
//FXMLDoc.Resync;
//ShowMessage(FXMLDoc.XML.Text);
ForceDomTofile(ASavetoPath);
end;
procedure TCutedFile.ForceDomTofile(APath:string);//Dom保存到文件
var
strmMemo:TMemoryStream;
strmString:TStringStream;
sEncry:string;
begin
FXMLDoc.NodeIndentStr:=#32#32;
sEncry:=FSecret.EncryptString(FormatXMLData(FXMLDoc.XML.Text),xmlKEY);//这是个加密函数
strmString:=TStringStream.Create(sEncry);
try
strmMemo:=TMemoryStream.Create;
try
strmMemo.LoadFromStream(strmString);
strmMemo.SaveToFile(APath);
finally
strmMemo.Free;
end;
finally
strmString.Free;
end;
end;