Solved

Build an XML document.

Posted on 2004-09-04
4
186 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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using YubiKey with REST API application 2 116
site launch date and last modified date 3 93
JAudiorecorder record freezing the app 29 67
Base1 Encode/Decode 3 77
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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