Solved

Build an XML document.

Posted on 2004-09-04
4
189 Views
Last Modified: 2013-11-19
Hello!

I need some help.

I have an application that builds a lot of xml documents.

I use the

TXMLDocument component but my problem is that this is to slow. (takes a lot of time when building hundred of thosand xml documents.)

Can  someone give me an example of how to build a xml document fast...
0
Comment
Question by:hulken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11982297
You can try some other XML parser, for example SAX, but I am not sure if for "hundred of thosand" elements it will help you, so that you will notice any difference.

SAX download page:
http://saxforpascal.sourceforge.net/index.html?downloads.html

Here you can see the advantages of SAX:
http://saxforpascal.sourceforge.net/saxdom.html

One of them is supposed to be the speed...
0
 
LVL 2

Expert Comment

by:wqclatre
ID: 11983537
It's not "hundred of thosand" elements in the same document. it's a lot of documents.


I realy don't need to parse the document. I just want to build the document.

(adding node by node).

I have a TObject with a lot of properties that I put in the XML document.
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11985100
Use the VirtualTreeview component from www.delphi-gems.com IT will cope with many million nodes no problems :)

It has been used for a similar purpose
http://www.soft-gems.net/VirtualTreeview/VTGallery.php

second item down and the item right down at the bottom :)

http://www.xmlblueprint.com/
uses virtual treeview

hope this helps

David
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 125 total points
ID: 11988867
Easiest way is by just writing them as textfiles... :-)

var
  AFile:TextFile;
  Buffer:Array[1..16*1024] of char; // Speeds up the files.
begin
  AssignFile(AFile,'Document1.xml');
  Rewrite(AFile);
  SetTextBuf(AFile, Buffer);
  WriteLn(AFile, '<?xml version="1.0" encoding="utf-8"?>');
  WriteLn(AFile, '<?xml-stylesheet type="text/xsl" href="CV.xslt"?>');// If you have a stylesheet...
  WriteLn(AFile, '<CurriculumVitae xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CV.xsd">'); // If you have a schema...
  WriteLn(AFile, '<Personal>');
  WriteLn(AFile, '<Name>Workshop Alex</Name>');
  WriteLn(AFile, '<Personal>');
  // And write whatever else you need to write...
  WriteLn(AFile, '</CurriculumVitae>'); // Final closing tag.
  CloseFile(AFile);
end;
(Beware of the special characters in XML: <> and &

Yeah, I know. It doesn't look that nice but if you're familiar with the XML syntax, this is the fastest way to CREATE new files. If you want to modify, better use one of the existing parsers. Parsers are slower in general, though...

People tend to forget that XML is just basically a textfile format. If you know what you're doing, writing them as textfiles is the fastest method to create a lot of them...
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 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