Solved

XML Documents

Posted on 2002-04-24
3
712 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 87
select query - oracle 16 100
Dev express lookupcombo 3 28
Installshield for Embarcadero EX 10.1 Berlin 4 40
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 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