这个问题是关于将 XML 数据从 LiveCode 堆栈写入文件。用户指南的第 6.7 章讨论了 LiveCode 提供的 XML 函数。我正在寻找展示如何构造 XML 文件并将其写入磁盘文件的示例。
http://support.runrev.com/tutorials/xmldemo.rev.gz是一个关于如何使用 LiveCode 的 revNNN XML 函数的教程堆栈。
它有一个例子
....
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
结果
<?xml version="1.0"?>
<employeeTable>
<employee IDnum="1">
<firstName>Steve</firstName>
<lastName>Jobs</lastName>
<roomNum>001</roomNum>
<phoneExt>345</phoneExt>
<parkingSlot>100</parkingSlot>
</employee>
</employeeTable>
是否有库通过提供便利功能使编写 XML 文本更容易,这样我在添加嵌套结构时就不需要跟踪节点?
就像是
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
编写几个这样的函数相对容易,但问题是。是否有既定的方法可以将 XML 文本写入 LiveCode 中的文件?