AGB  ·  Datenschutz  ·  Impressum  







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

XML Problem

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

n/a Beiträge
 
#1

XML Problem

  Alt 4. Jan 2010, 23: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
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

Re: XML Problem

  Alt 4. Jan 2010, 23:28
Zitat von nanix:
I spoted this sample code while browsing google its for FPC but it dosent work in delphi
Nice. And what do you expect from us now? Guessing the error messages?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#3

Re: XML Problem

  Alt 4. Jan 2010, 23:29
No i am asking why its not compatible with delphi.
  Mit Zitat antworten Zitat
Benutzerbild von mirage228
mirage228

Registriert seit: 23. Mär 2003
Ort: Münster
3.750 Beiträge
 
Delphi 2010 Professional
 
#4

Re: XML Problem

  Alt 4. Jan 2010, 23:49
I see two lines which definitely will not work:

1.)
  {$I unit1.lrs} Delphi form resources are not included in that way. You have to write:
  {$R *.dfm} Of course this requires a Delphi DFM file which contains the GUI elements of the Form corresponding to the Unit (Unit.dfm) to be present. As far as I know Delphi is not able to load those Lazarus resource files.

2.)
.ChildNodes.Item[0].AppendChild(parentNode); // insert a childnode in respective parent node This is a syntax error. There must be a suitable object instance before the dot "." at the beginning of the line.
David F.

May the source be with you, stranger.
PHP Inspection Unit (Delphi-Unit zum Analysieren von PHP Code)
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5

Re: XML Problem

  Alt 4. Jan 2010, 23:53
Zitat von nanix:
No i am asking why its not compatible with delphi.
If it is not compatible there must be error messages from the compiler. So why don't you inform us about these error messages? Don't you think this would make it a bit eaysier for us?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#6

Re: XML Problem

  Alt 5. Jan 2010, 12:39
I used a XMLDocument and empty form all with 2010 delphi.

Next errors i got.

Zitat:
[DCC Error] Unit2.pas(29): E2003 Undeclared identifier: 'TDOMNode'
[DCC Error] Unit2.pas(32): E2250 There is no overloaded version of 'Create' that can be called with these arguments
[DCC Error] Unit2.pas(35): E2035 Not enough actual parameters
[DCC Error] Unit2.pas(36): E2003 Undeclared identifier: 'Appendchild'
[DCC Error] Unit2.pas(40): E2035 Not enough actual parameters
[DCC Error] Unit2.pas(41): E2003 Undeclared identifier: 'TDOMElement'
[DCC Error] Unit2.pas(41): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(42): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(45): E2035 Not enough actual parameters
[DCC Error] Unit2.pas(47): E2003 Undeclared identifier: 'CreateTextNode'
[DCC Error] Unit2.pas(48): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(49): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(49): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(52): E2035 Not enough actual parameters
[DCC Error] Unit2.pas(54): E2003 Undeclared identifier: 'CreateTextNode'
[DCC Error] Unit2.pas(55): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(56): E2029 Statement expected but '.' found
[DCC Error] Unit2.pas(56): E2066 Missing operator or semicolon
[DCC Error] Unit2.pas(58): E2003 Undeclared identifier: 'writeXMLFile'
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.136 Beiträge
 
Delphi 12 Athens
 
#7

Re: XML Problem

  Alt 5. Jan 2010, 13:17
Interfaces (IXMLDocument) > unit XMLIntf and XMLDOM
Classes (TXMLDocument) > unit XMLDoc

TDOMNode are daclared in unit XDOM (Extended Document Object Model) or OXMLDOM (Open XML)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#8

Re: XML Problem

  Alt 5. Jan 2010, 13:25
Or let me ask a more simple question how to generate an XML with delphi and not FPC.
I just cant fix this code.
  Mit Zitat antworten Zitat
Antwort Antwort


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 07:13 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz