如何创建新的XML
如何在XML中加入节点

解决方案 »

  1.   

    CreateNode('节点名称', ntElement, '节点数据');
      

  2.   

    procedure TForm1.Button3Click(Sender: TObject);
    var
    iXml:IDomDocument;
    iRoot,iNode,iNode2,iChild,iAttrbute:IDomNode;
    begin
            form1.XMLDocument1.Active:=false;
            form1.XMLDocument1.XML.Text:='';
            form1.XMLDocument1.Active:=true;        iXml:=form1.XMLDocument1.DOMDocument ;
            iRoot:=iXml.appendChild(iXml.createElement('xml'));        iNode:=iRoot.appendChild(iXml.createElement('test'));
            iNode.appendChild(iXml.createElement('test2'));
            iChild:=iNode.appendChild(iXml.createElement('test3'));
            iChild.appendChild(iXml.createElement('simplevalue'));
            iNode.insertBefore(iXml.createElement('test4'),iChild);        iNode2:=iNode.cloneNode(true);
            iRoot.appendChild(iNode2);        iAttrbute:=iXml.createAttribute('color');
            iAttrbute.nodeValue:='red';
            iNode2.attributes.setNamedItem(iAttrbute);
            form1.XMLDocument1.SaveToFile('c:\test.xml');
            showmessage('保存文件成功');
            form1.Memo1.Text:=FormatXmlData(form1.XMLDocument1.XML.Text);
    end;