5

I have used the following code to create the XML Document :

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;

I get the output in memXMLOutput but the XML document does not show the output when seen in Notepad ot IE. where is the problem? Thanks in advance

4
  • 4
    Congratulations, you have posted the ten thousandth question in the Delphi tag. Commented Jul 8, 2011 at 13:16
  • Huh! +1 for the ten thousandth Delphi question! Commented Jul 8, 2011 at 13:17
  • YIPEE!!!! i am a master of the world Commented Jul 8, 2011 at 13:18
  • unobvious get, should post stackoverflow.com/questions/6666666 next time Commented Jul 8, 2011 at 14:15

1 Answer 1

6

Remove this:

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

and add something like this after the code is done creating the XML document:

XMLDoc.SaveToFile('C:\Documents and Settings\a\Desktop\New Text Document.xml');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.