Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Pontesegger2014-11-25 11:41:11 +0000
committerChristian Pontesegger2014-11-25 11:41:11 +0000
commitb038bfb3618e74ede7a6e3be32251e813409cb92 (patch)
tree62479637997e171f3bf5c994b196cd18db003bbd /JavaScript Beginner Tutorial
parent39b427250fee4dca7b64a771afea8702932fac5d (diff)
downloadorg.eclipse.ease.scripts-b038bfb3618e74ede7a6e3be32251e813409cb92.tar.gz
org.eclipse.ease.scripts-b038bfb3618e74ede7a6e3be32251e813409cb92.tar.xz
org.eclipse.ease.scripts-b038bfb3618e74ede7a6e3be32251e813409cb92.zip
added simple XML handling example
Diffstat (limited to 'JavaScript Beginner Tutorial')
-rw-r--r--JavaScript Beginner Tutorial/02 File IO/03 XML handling.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/JavaScript Beginner Tutorial/02 File IO/03 XML handling.js b/JavaScript Beginner Tutorial/02 File IO/03 XML handling.js
new file mode 100644
index 0000000..bc1c3f5
--- /dev/null
+++ b/JavaScript Beginner Tutorial/02 File IO/03 XML handling.js
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Christian Pontesegger and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Pontesegger - initial API and implementation
+ *******************************************************************************/
+
+// change location according to your system
+const
+FILE_LOCATION = "/tmp/testfile.txt";
+// const FILE_LOCATION = "C:\\temp\\testfile.txt";
+
+// create a simple XML document
+var memento = org.eclipse.ui.XMLMemento.createWriteRoot("root");
+var person = memento.createChild("person");
+person.createChild("name").putTextData("Christian");
+person.createChild("profession").putTextData("Script guru");
+person.createChild("age").putInteger("guess", 34);
+
+// write to disk
+loadModule('/System/Resources');
+writeFile(FILE_LOCATION, memento);
+
+// create a shortcut for XMLMemento
+var XMLMemento = org.eclipse.ui.XMLMemento;
+
+// re-read XML
+var memento = XMLMemento.createReadRoot(new java.io.FileReader(FILE_LOCATION));
+print("Name: " + memento.getChild("person").getChild("name").getTextData());

Back to the top