Template:XMLParse: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==== VectorScript ==== <code lang="pas"> PROCEDURE Example; CONST userFolder = 2; xmlFile = 'Preferences.xml'; xmlRoot = '/VectorWorksPreferences/General'; VAR xml...") |
Mbvelichkova (talk | contribs) |
||
Line 3: | Line 3: | ||
PROCEDURE Example; | PROCEDURE Example; | ||
CONST | CONST | ||
userFolder = | userFolder = 15; | ||
xmlFile = 'Preferences.xml'; | xmlFile = 'VectorWorks Preferences.xml'; | ||
xmlRoot = '/VectorWorksPreferences/General'; | xmlRoot = '/VectorWorksPreferences/General'; | ||
VAR | VAR | ||
Line 37: | Line 37: | ||
END; | END; | ||
RUN(Example);</code> | RUN(Example);</code> | ||
==== Python ==== | ==== Python ==== | ||
<code lang="py"> | <code lang="py"> |
Revision as of 08:02, 22 May 2015
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 = 2 xmlFile = '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()