请问在delphi中如何生成这样一个xml文件(路径为c:\test.xml),请给出代码
<?xml version="1.0" encoding="ISO-8859-1" ?> <breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian </description>
<calories>650</calories>
</food>
</breakfast_menu>
<?xml version="1.0" encoding="ISO-8859-1" ?> <breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian </description>
<calories>650</calories>
</food>
</breakfast_menu>
IXMLDOMElement
ReWrite(F);
writeln(F, '<?xml version="1.0" encoding="ISO-8859-1"?>');
writeln(F, '<breakfast_menu>');
writeln(F, #9 + '<food>');
writeln(F, #9 + #9 + '<name>Belgian Waffles</name>');
writeln(F, #9 + #9 + '<price>$5.95</price>');
writeln(F, #9 + #9 + '<description>two of our famous Belgian </description>');
writeln(F, #9 + #9 + '<calories>650</calories>');
writeln(F, #9 + '</food>');
writeln(F, '</breakfast_menu>');
CloseFile(F);方法二:(也就是二楼说的方法)var
XmlDoc: IXMLDomDocument;
xmlStr: string;
fp: integer;
root,Node,ChildNode: IXmlNode;
begin
XmlDoc := CreateOleObject('Microsoft.XMLDOM')
as IXMLDomDocument;
//对XmlDoc对象操作
root := XmlDoc.CreateElement('breakfast_menu');
XmlDoc.AppendChild(root);
Node := XmlDoc.CreateElement('food');
root.AppendChild(Node);
//name
ChildNode := XmlDoc.CreateElement('name');
Node.AppendChild(ChildNode);
ChildNode.AppendChild(XmlDoc.CreateTextNode('Belgian Waffles'));
//price
ChildNode := XmlDoc.CreateElement('price');
Node.AppendChild(ChildNode);
ChildNode.AppendChild(XmlDoc.CreateTextNode('$5.95'));
//description
ChildNode := XmlDoc.CreateElement('description');
Node.AppendChild(ChildNode);
ChildNode.AppendChild(XmlDoc.CreateTextNode('two of our famous Belgian'));
//calories
ChildNode := XmlDoc.CreateElement('calories');
Node.AppendChild(ChildNode);
ChildNode.AppendChild(XmlDoc.CreateTextNode('650')); XmlDoc.Save('Text.xml');
end;
ReWrite(F);
writeln(F, '<?xml version="1.0" encoding="ISO-8859-1"?>');
writeln(F, '<breakfast_menu>');
writeln(F, #9 + '<food>');
writeln(F, #9 + #9 + '<name>Belgian Waffles</name>');
writeln(F, #9 + #9 + '<price>$5.95</price>');
writeln(F, #9 + #9 + '<description>two of our famous Belgian </description>');
writeln(F, #9 + #9 + '<calories>650</calories>');
writeln(F, #9 + '</food>');
writeln(F, '</breakfast_menu>');
CloseFile(F);