[fpc-pascal] TDOMElement and multiple attributes
Mattias Gaertner
nc-gaertnma at netcologne.de
Mon Mar 21 15:59:28 CET 2011
On Mon, 21 Mar 2011 15:34:28 +0100
Reimar Grabowski <reimgrab at web.de> wrote:
>[...]
> I am to lazy to attach the code, so here it is (you should know how to get it into Lazarus without too much hassle :) ):
>
> program xmlattributes;
>
> {$mode objfpc}{$H+}
>
> uses
> {$IFDEF UNIX}{$IFDEF UseCThreads}
> cthreads,
> {$ENDIF}{$ENDIF}
> Classes, SysUtils, CustApp,
> DOM, XMLWrite;
> type
>
> { TXMLAttributes }
>
> TXMLAttributes = class(TCustomApplication)
> protected
> procedure DoRun; override;
> public
> end;
>
> { TXMLAttributes }
>
> procedure TXMLAttributes.DoRun;
> var
> ErrorMsg: String;
> Document: TXMLDocument;
> RootNode, Node: TDOMNode;
> begin
> try
> Document:=TXMLDocument.Create;
> RootNode:=Document.CreateElement('ROOT');
> TDOMElement(RootNode).SetAttribute('someAttrib', 'someValue');
> Document.AppendChild(RootNode);
>
> RootNode:=Document.DocumentElement;
> Node:=Document.CreateElement('SomeNode');
> TDOMElement(Node).SetAttribute('aaaAttribute', '1');
> TDOMElement(Node).SetAttribute('aAttribute', '2');
> TDOMElement(Node).SetAttribute('ccAttribute', '4');
> TDOMElement(Node).SetAttribute('bAttribute', '3');
> RootNode.Appendchild(Node);
>
> WriteXMLFile(Document, 'test.xml');
> finally
> Document.Free;
> end;
>
> // stop program loop
> Terminate;
> end;
>
> var
> Application: TXMLAttributes;
>
> {$R *.res}
>
> begin
> Application:=TXMLAttributes.Create(nil);
> Application.Title:='XMLAttributes';
> Application.Run;
> Application.Free;
> end.
Thanks.
> someone at somewhere:~/pascal/Projects/xmldemo$ cat test.xml
> <?xml version="1.0"?>
> <ROOT someAttrib="someValue">
> <SomeNode aAttribute="2" bAttribute="3" ccAttribute="4" aaaAttribute="1"/>
> </ROOT>
>
> Looks like the order is governed by the length of the attribute name first and then alphabetically.
Yes, that is what CompareDOMStrings does.
Probably for speed reasons.
This function is fixed in the code.
Mattias
More information about the fpc-pascal
mailing list