Solved

XML Documents

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now