Solved

XML Documents

Posted on 2002-04-24
3
713 Views
Last Modified: 2012-06-27
Hi there

I can parse an existing XML document using the TXMLDocument component that ships with Delphi but I've got trouble creating a new document using the component.

I've tried createnode / and addnode but then most of the properties and methods are grayed out.

Please help
 If possible a small bit of sample code would help a lot.
  Fick
0
Comment
Question by:jfvd
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 200 total points
ID: 6967632
Here is a simple sample

TForm1 = class(TForm)
    btnSimple: TButton;
    Memo1: TMemo;
    procedure btnSimpleClick(Sender: TObject);
   rivate
    { Private declarations }
  public
    { Public declarations }
  end;


procedure TForm1.btnSimpleClick(Sender: TObject);
var
  iXml: IDOMDocument;
  iRoot, iNode, iNode2, iChild, iAttribute: IDOMNode;
begin
  // empty the document
  XMLDoc.Active := False;
  XMLDoc.XML.Text := '';
  XMLDoc.Active := True;

  // root
  iXml := XmlDoc.DOMDocument;
  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
  Memo1.Lines.Text := FormatXMLData (XMLDoc.XML.Text);
end;


Shane
0
 

Author Comment

by:jfvd
ID: 6968329
Thanx Shane

I actually got it to work now.

Do you always have to use the DOMDocument to create "XML"? Also do you perhaps know what will happen if I've got a really large document to build before saving it to disk. Wouldn't I run into resource problems

Fick
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 6969964
I always use it. You can of course create on by hand, but... Like always, applications are dependent on memory, therefore, you would have to test how large of a document you can store with the resources you have, or the potential end user will have.

Shane
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why can't I create any project with my delphi EXE file? 6 39
creating threads in delphi 1 136
Convert MS Word document to a PDF file 9 91
Graphics32 under Delphi 10.1 Berlin 2 105
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question