Hallo,
I'm just wondering if it is possible to load more than one xml file into a sketch.
I have several xml files of this structure.
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <pulses>
- <circle>
- <data posX="230" posY="121" col="200" rad="20"/>
- </circle>
- <circle>
- <data posX="139" posY="201" col="130" rad="23"/>
- </circle>
- <circle>
- <data posX="230" posY="243" col="54" rad="17"/>
- </circle>
- </pulses>
When executing the script it only loads and prints out all attributes of the first xml file.
Is there a way how to load several xml files separately into one sketch? This would be great!!!!
Thanks in advance!!
- import proxml.*;
- // ----------------------------------------------------------------------
- // GLOBAL VARIABLES
- // ----------------------------------------------------------------------
- XMLInOut xmlIO;
- XMLInOut xmlIO1;
- proxml.XMLElement myList;
- proxml.XMLElement myList1;
- // ----------------------------------------------------------------------
- // BUILT-IN FUNCTIONS
- // ----------------------------------------------------------------------
- void setup() {
- size(400, 400);
- readData();
- readData1();
- }
- void xmlEvent(proxml.XMLElement element) {
- myList = element;
- myList1 = element;
- }
- void draw() {
- }
- // ----------------------------------------------------------------------
- // READ DATA
- // ----------------------------------------------------------------------
- void readData () {
- xmlIO = new XMLInOut(this);
- try {
- xmlIO.loadElement("test.xml");
- }
- catch (Exception e) {
- xmlEvent(new proxml.XMLElement("myList"));
- }
- while (myList == null) {
- }
- proxml.XMLElement[] allData = myList.getChildren();
- for (int i = 0; i< allData.length; i++) {
- proxml.XMLElement data = allData[i];
- proxml.XMLElement param = data.getChild(0);
- if (!param.getName().equals("data")) continue;
- String posX, posY, col, rad;
- posX = param.getAttribute ("posX");
- posY = param.getAttribute("posY");
- col = param.getAttribute("col");
- rad = param.getAttribute("rad");
- println("posX:" + posX + " " + "posY:" + posY + " " + "col:" + col + " " + "rad:" + rad);
- }
- }
- void readData1() {
- xmlIO1 = new XMLInOut(this);
- try {
- xmlIO1.loadElement("test1.xml");
- }
- catch (Exception e) {
- xmlEvent(new proxml.XMLElement("myList1"));
- }
- while (myList1 == null) {
- }
- proxml.XMLElement[] allData = myList1.getChildren();
- for (int i = 0; i< allData.length; i++) {
- proxml.XMLElement data = allData[i];
- proxml.XMLElement param = data.getChild(0);
- if (!param.getName().equals("data")) continue;
- String posX, posY, col, rad;
- posX = param.getAttribute ("posX");
- posY = param.getAttribute("posY");
- col = param.getAttribute("col");
- rad = param.getAttribute("rad");
- println("posX:" + posX + " " + "posY:" + posY + " " + "col:" + col + " " + "rad:" + rad);
- }
- }
1