Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Everybody is just writing about negative issues so let's stress some positive issues. Errr, the only positive issue - less (in some cases <strong>much</strong> less) typing.</p> <p>I wrote GpFluentXMLBuilder just because I hate typing tons of code while creating XML documents. Nothing more and nothing less.</p> <p>The good point with fluent interfaces is that you don't have to use them in the fluent manner if you hate the idiom. They are completely usable in a traditional way.</p> <p>EDIT: A point for the "shortness and readability" view.</p> <p>I was debugging some old code and stumbled across this:</p> <pre><code>fdsUnreportedMessages.Add(CreateFluentXml .UTF8 .AddChild('LogEntry') .AddChild('Time', Now) .AddSibling('Severity', msg.MsgID) .AddSibling('Message', msg.MsgData.AsString) .AsString); </code></pre> <p>I knew immediately what the code does. If, however, the code would look like this (and I'm not claiming that this even compiles, I just threw it together for demo):</p> <pre><code>var xmlData: IXMLNode; xmlDoc : IXMLDocument; xmlKey : IXMLNode; xmlRoot: IXMLNode; xmlDoc := CreateXMLDoc; xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')); xmlRoot := xmlDoc.CreateElement('LogEntry'); xmlDoc.AppendChild(xmlRoot); xmlKey := xmlDoc.CreateElement('Time'); xmlDoc.AppendChild(xmlKey); xmlData := xmlDoc.CreateTextNode(FormatDateTime( 'yyyy-mm-dd"T"hh":"mm":"ss.zzz', Now)); xmlKey.AppendChild(xmlData); xmlKey := xmlDoc.CreateElement('Severity'); xmlDoc.AppendChild(xmlKey); xmlData := xmlDoc.CreateTextNode(IntToStr(msg.MsgID)); xmlKey.AppendChild(xmlData); xmlKey := xmlDoc.CreateElement('Message'); xmlDoc.AppendChild(xmlKey); xmlData := xmlDoc.CreateTextNode(msg.MsgData.AsString); xmlKey.AppendChild(xmlData); fdsUnreportedMessages.Add(xmlKey.XML); </code></pre> <p>I would need quite some time (and a cup of coffee) to understand what it does.</p> <p>EDIT2: </p> <p>Eric Grange made a perfectly valid point in comments. In reality, one would use some XML wrapper and not DOM directly. For example, using OmniXMLUtils from the <a href="http://www.omnixml.com" rel="noreferrer">OmniXML</a> package, the code would look like that:</p> <pre><code>var xmlDoc: IXMLDocument; xmlLog: IXMLNode; xmlDoc := CreateXMLDoc; xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction( 'xml', 'version="1.0" encoding="UTF-8"')); xmlLog := EnsureNode(xmlDoc, 'LogEntry'); SetNodeTextDateTime(xmlLog, 'Time', Now); SetNodeTextInt(xmlLog, 'Severity', msg.MsgID); SetNodeText(xmlLog, 'Message', msg.MsgData.AsString); fdsUnreportedMessages.Add(XMLSaveToString(xmlDoc)); </code></pre> <p>Still, I prefer the fluent version. [And I never ever use code formatters.]</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload