AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

XML Problem

Ein Thema von nanix · begonnen am 5. Jan 2010 · letzter Beitrag vom 5. Jan 2010
 
nanix
(Gast)

n/a Beiträge
 
#1

XML Problem

  Alt 5. Jan 2010, 00:19
Hey,


I spoted this sample code while browsing google its for FPC but it dosent work in delphi

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  xdoc: TXMLDocument; // variable to document
  RootNode, parentNode, nofilho: TDOMNode; // variable to nodes
begin
  //create a document
  xdoc := TXMLDocument.create;
 
  //create a root node
  RootNode := xdoc.CreateElement('register');
  Xdoc.Appendchild(RootNode); // save root node
 
  //create a parent node
  RootNode:= xdoc.DocumentElement;
  parentNode := xdoc.CreateElement('usuario');
  TDOMElement(parentNode).SetAttribute('id', '001'); // create atributes to parent node
  RootNode.Appendchild(parentNode); // save parent node
 
  //create a child node
  parentNode := xdoc.CreateElement('nome'); // create a child node
  //TDOMElement(parentNode).SetAttribute('sexo', 'M'); // create atributes
  nofilho := xdoc.CreateTextNode('Fernando'); // insert a value to node
  parentNode.Appendchild(nofilho); // save node
  RootNode.ChildNodes.Item[0].AppendChild(parentNode); // insert child node in respective parent node
 
  //create a child node
  parentNode := xdoc.CreateElement('idade'); // create a child node
  //TDOMElement(parentNode).SetAttribute('ano', '1976'); // create atributes
  nofilho := xdoc.CreateTextNode('32'); // insert a value to node
  parentNode.Appendchild(nofilho); // save node
  .ChildNodes.Item[0].AppendChild(parentNode); // insert a childnode in respective parent node
 
  writeXMLFile(xDoc,'teste.xml'); // write to XML
  Xdoc.free; // free memory
end;
 
initialization
  {$I unit1.lrs}
 
end.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:33 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz