Talk:XML Tutorial

From Free Pascal wiki
Revision as of 00:49, 30 November 2019 by Rfc1394 (talk | contribs) (→‎Writing XML files)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Docelement is not the root of XML tree in DOM

The first sample has

   ReadXMLFile(Doc, 'test.xml');
   PassNode := Doc.DocumentElement.FindNode('password');

Does this mean that DocumentElement is the representation of the top of the XML document in DOM form? Can you also write to that to e.g. change <?xml version="1.0"?> to <?xml version="1.0" standalone="yes"?>

--BigChimp 09:36, 24 July 2011 (CEST)

No, the top of XML document is represented by the Document object itself. DocumentElement is a regular TDOMElement object, which is a child of Document. The reason of having a separate DocumentElement property is that the document may contain comments and processing instructions before and after the root element, and it also may contain a DTD node, so condition DocumentElement=Document.FirstChild is not always true.

The XML declaration <?xml version="1.0"?> is not a part of node tree. DOM specification levels 1 and 2 do not provide any means to modify it, but DOM level 3 introduces Document.xmlVersion, Document.xmlEncoding and Document.xmlStandalone properties for this purpose. xmlStandalone is not yet implemented by fcl-xml.

Gorelkin 09:11, 25 July 2011 (CEST)

Thanks! This clears it up! --BigChimp 14:04, 26 July 2011 (CEST)

Required uses clauses - seems fixed?

The example routines, taken "as is", does not compile. Need to tell what units are needed in the uses section, at least (no, I don't know what they are) --Kormoran 14:19, 26 March 2011 (CET)

The writeXMLFile example does not work unless laz2_XMLWrite is used

I am using Lazarus 1.0.10 (FPC 2.6.2) on Windows 7. First I tried the example code as is, but it did not work. But when I used the laz2_* equivalents, it worked.

Writing XML files

It looks like the vast majority of this tutorial covers reading XML files, and the coverage of writing them, is woefully deficient. To put it bluntly, the coverage sucks.

I have most of it down, more-or-less from web searches: writing a root node, no problem. writing a child node w/o entries (just attributes), no problem. writing a child with values, no problem. Write a second root node: raises exception! (Never mind why I'd want multiple root nodes, I have reasons. Like testing the reader). So there's something here I don't really understand. I'm not sure what I'm doing wrong and the documentation on how to write files is weak, thin, and unclear. Paul Robinson Rfc1394 (talk) 14:36, 29 November 2019 (CET)

Update: I had decided to use XML for creating a configuration file for a program I'm writing. I have since found out that properly formed XML files have one root. But I have learned some things in the process of experimenting with XML writing, and I think I will write up some details for the article. Rfc1394 (talk) 00:49, 30 November 2019 (CET)