Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to construct and write an XML file?
    text
    copied!<p>This question ia about writing XML data from a LiveCode stack to a file. Chapter 6.7 of the User's guide talks about the XML functions LiveCode provides. I am looking for examples which show how to construct an XML file and write it to a disk file.</p> <p><a href="http://support.runrev.com/tutorials/xmldemo.rev.gz" rel="nofollow">http://support.runrev.com/tutorials/xmldemo.rev.gz</a> is a tutorial stack about how to use the revNNN XML functions of LiveCode.</p> <p>It has an example</p> <pre><code> .... local tDocID, tParentNode, tSubNode -- get the document ID for the current XML tree put fld "DocID" into tDocID -- specify the root node for the XML tree put "/employeeTable" into tParentNode revAddXMLNode tDocID, tParentNode, "employee", "" put the result into tSubNode -- add the IDnum attribute to the newly created data record revSetXMLAttribute tDocID, tSubNode, "IDnum", "1" -- add the remaining data elements, checking for error after each addition revAddXMLNode tDocID, tSubNode, "firstName", "Steve" revAddXMLNode tDocID, tSubNode, "lastName", "Jobs" revAddXMLNode tDocID, tSubNode, "roomNum", "001" revAddXMLNode tDocID, tSubNode, "phoneExt", "345" revAddXMLNode tDocID, tSubNode, "parkingSlot", 100 </code></pre> <p>The result</p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;employeeTable&gt; &lt;employee IDnum="1"&gt; &lt;firstName&gt;Steve&lt;/firstName&gt; &lt;lastName&gt;Jobs&lt;/lastName&gt; &lt;roomNum&gt;001&lt;/roomNum&gt; &lt;phoneExt&gt;345&lt;/phoneExt&gt; &lt;parkingSlot&gt;100&lt;/parkingSlot&gt; &lt;/employee&gt; &lt;/employeeTable&gt; </code></pre> <p>Are there libraries which make writing XML texts easier by providing convenience functions so that I do not need to keep track of nodes when adding nested structures? </p> <p>Something like</p> <pre><code>startXML "theEmployees.xml" -- gives the file name startTag "employeetable" startTag "employee" addAttribute "IDnum", 1 startTag "firstName" writeContent "Steve" closeTag -- or writeNode "lastname", "Jobs" writeNode "roomnum", "001" -- .... closeTag -- employee closeTag -- employeeTable closeXML </code></pre> <p>It is relatively easy to write a couple of functions like this but the question is. Are there established ways of writing out XML text to a file in LiveCode?</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