Solved

Build an XML document.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

808 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