VS:ReadXMLFile: Difference between revisions
Jump to navigation
Jump to search
(add remark) |
m (Transfer Orso to _c_) |
||
Line 47: | Line 47: | ||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ||
<remark> | <remark> | ||
[[User:CBM-c-|_c_]] (2016.06.16): Requires a HSF path (with colon) on Mac. | |||
</remark> | </remark> | ||
Latest revision as of 07:12, 30 December 2020
.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix
Description
Reads an XML file. The entire file is read in, and parsed. Once this has been done, the calling application can then use the following accessor functions to retrieve and modify the data within that file. whichPath is the directory specifier; if whichPath is -1, the filename is taken by itself, without prepending a directory onto it.
FUNCTION ReadXMLFile(
XMLHandle :LONGINT;
whichPath :INTEGER;
filename :STRING) :INTEGER;
def vs.ReadXMLFile(XMLHandle, whichPath, filename): return INTEGER
Parameters
XMLHandle LONGINT whichPath INTEGER filename STRING
Remarks
_c_ (2016.06.16): Requires a HSF path (with colon) on Mac.
Example
VectorScript
PROCEDURE Example; CONST userFolder = 15; xmlFile = 'VectorWorks Preferences.xml'; xmlRoot = '/VectorWorksPreferences/General'; VAR xmlID :LONGINT; value :STRING; elementPath :STRING; PROCEDURE ShowPathAndValue(path :STRING); BEGIN IF GetElementValue(xmlID, path, value) = 0 THEN BEGIN AlrtDialog(Concat(path, Chr(13), value)); END ELSE BEGIN AlrtDialog(Concat('Problem in GetElementValue.', Chr(13), 'Path = ', path)); END; END; BEGIN xmlID := InitXML; IF ReadXMLFile(xmlID, userFolder, xmlFile) = 0 THEN BEGIN IF GetFirstChild(xmlID, xmlRoot, elementPath) = 0 THEN BEGIN ShowPathAndValue(Concat(xmlRoot, '/', elementPath)); WHILE GetPreviousElement(xmlID, Concat(xmlRoot, '/', elementPath), elementPath) = 0 DO BEGIN ShowPathAndValue(Concat(xmlRoot, '/', elementPath)); END; END ELSE BEGIN AlrtDialog('Problem in GetFirstChild'); END; END ELSE BEGIN AlrtDialog('Problem in ReadXMLFile'); END; xmlID := ReleaseXML(xmlID); END; RUN(Example);
Python
def ShowPathAndValue( path ): hasErr, value = vs.GetElementValue(xmlID, path) if hasErr == 0: vs.AlrtDialog(vs.Concat(path, vs.Chr(13), value)) else: vs.AlrtDialog(vs.Concat('Problem in GetElementValue.', vs.Chr(13), 'Path = ', path)) def Example(): userFolder = 15 xmlFile = 'VectorWorks Preferences.xml' xmlRoot = '/VectorWorksPreferences/General' global xmlID xmlID = vs.InitXML() if vs.ReadXMLFile(xmlID, userFolder, xmlFile) == 0: hasErr, elementPath = vs.GetFirstChild(xmlID, xmlRoot) if hasErr == 0: ShowPathAndValue(vs.Concat(xmlRoot, '/', elementPath)) hasErr, elementPath = vs.GetPreviousElement(xmlID, vs.Concat(xmlRoot, '/', elementPath)) while hasErr == 0: ShowPathAndValue(vs.Concat(xmlRoot, '/', elementPath)) hasErr, elementPath = vs.GetPreviousElement(xmlID, vs.Concat(xmlRoot, '/', elementPath)) else: vs.AlrtDialog('Problem in GetFirstChild') else: vs.AlrtDialog('Problem in ReadXMLFile') xmlID = vs.ReleaseXML(xmlID) xmlID = 0 Example()
Version
Availability: from All Versions
This is drop-in function.