gpt4 book ai didi

delphi - 如何在 Delphi 7 中使用 TXML 文档创建 XML 文件

转载 作者:行者123 更新时间:2023-12-03 15:10:46 25 4
gpt4 key购买 nike

我使用了以下代码来创建 XML 文档:

procedure TForm1.btnCreateXMLClick(Sender: TObject);
var
rootName:string;
childName:string;
attrChild:string;
iXml: IDOMDocument;
iRoot, iNode, iNode2, iChild, iAttribute: IDOMNode;
begin
XMLDoc.Active:=false;
XMLDoc.XML.Text:='';
XMLDoc.Active:=true;
XMLDoc.FileName:='C:\Documents and Settings\a\Desktop\New Text Document.xml';
iXml := XmlDoc.DOMDocument;
//iRoot:=iXml.documentElement(iXml.createElement('xml'));
iRoot := iXml.appendChild(iXml.createElement ('xml'));
// node "test"
iNode := iRoot.appendChild (iXml.createElement ('test'));
iNode.appendChild (iXml.createElement ('test2'));
iChild := iNode.appendChild (iXml.createElement ('test3'));
iChild.appendChild (iXml.createTextNode('simple value'));
iNode.insertBefore (iXml.createElement ('test4'), iChild);

// node replication
iNode2 := iNode.cloneNode (True);
iRoot.appendChild (iNode2);

// add an attribute
iAttribute := iXml.createAttribute ('color');
iAttribute.nodeValue := 'red';
iNode2.attributes.setNamedItem (iAttribute);

// show XML in memo
memXMLOutput.Lines.Text:=FormatXMLData(XMLDoc.XML.Text);
end;

我在 memXMLOutput 中获得输出,但 XML 文档在记事本或 IE 中查看时不显示输出。哪里有问题?提前致谢

最佳答案

删除这个:

XMLDoc.FileName:='C:\Documents and Settings\a\Desktop\New Text Document.xml';

并在代码创建完 XML 文档后添加如下内容:

XMLDoc.SaveToFile('C:\Documents and Settings\a\Desktop\New Text Document.xml');

关于delphi - 如何在 Delphi 7 中使用 TXML 文档创建 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6624914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com