Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Setting XML Attributes in Delphi
// Modify the crisp.xml document by relocating some information // as attributes instead of child nodes. procedure TForm1.Example3Click(Sender: TObject); var xml: IChilkatXml; outXml: IChilkatXml; node: IChilkatXml; langNode: IChilkatXml; begin xml := CoChilkatXml.Create(); outXml := CoChilkatXml.Create(); // Load the input document. xml.LoadXmlFile('crisp.xml'); // Iterate over the "DOC" nodes by calling FirstChild // followed by NextSibling2 repeatedly until it returns false. node := xml.FirstChild(); while (node <> nil) do begin langNode := node.FindChild('Language'); if (langNode <> nil) then begin // Add the language information as an attribute of the "DOC" node. node.AddAttribute('language',langNode.Content); // Remove the "Language" node from the document because the // information is now stored as an attribute of the parent. langNode.RemoveFromTree(); end; // Move to the next sibling. The internal reference within node is updated // to the node's next sibling. If no siblings remain, it returns 0. if (node.NextSibling2() = 0) then node := nil; end; xml.SaveXml('CreateAttributes.xml'); end; |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.