“The Extensible Markup Language XML has become the standard for exchanging structured data in Internet applications. proXML allows you to easily integrate and manipulate this data in Processing.”
http://creativecomputing.cc/p5libs/proxml/index.htm
I have this file generated in Inkscape - drawing08.svg - with one rectangle. It basically includes the following:
- <svg
- <defs…
- <sodipodi…
- <metadata…
- <g
- inkscape:label="Layer 1"
- inkscape:groupmode="layer"
- id="layer1"
- transform="translate(-8.5714245,593.94476)">
- <rect…
- </g>
- </svg>
Sketch xml_02 includes this code:
- import proxml.XMLInOut;
- import proxml.XMLElement;
- XMLInOut xmlIO;
- void setup()
- {
- size(400, 400);
- main = loadShape("drawing08.svg");
- xmlIO = new XMLInOut(this);
- xmlIO.loadElement("drawing08.svg"); // Use this method to load an xml file.
- noLoop();
- }
- void xmlEvent(XMLElement element) {
Add this code:
- // get children of root element
- XMLElement[] children = element.getChildren();
- for(int i = 0; i < children.length;i++)
- {
- XMLElement child = children[i];
- println("child index: " + str(i) + child);
- }
Console shows:
children index: 0<defs…
children index: 1<sodipodi…
children index: 2<metadata…
children index: 3<g…
Add this code:
- // get attributes for child 3 - <g
- Println(“children[3]”);
- String[] attributes = children[3].getAttributes();
- for(int j = 0; j < attributes.length; j++)
- {
- println("attributes index: " + str(j) + attributes[j]);
- }
Console shows:
children[3]
attributes index: 0inkscape:label
attributes index: 1transform
attributes index: 2inkscape:groupmode
attributes index: 3id
Question: Why are attributes assigned in different order than svg file?
Add this code:
- // look for attribute "transform"
- for(int k = 0; k < attributes.length; k++)
- {
- String matchAtt = "transform";
- if(attributes[k] == matchAtt)
- {
- println(attributes[k] + " EQUAL " + matchAtt);
- }
- else
- {
- println(attributes[k] + " NOT EQUAL " + matchAtt);
- }
- }
Console shows:
inkscape:label NOT EQUAL transform
transform NOT EQUAL transform
inkscape:groupmode NOT EQUAL transform
id NOT EQUAL transform
Question: Why is transform NOT EQUAL?
Add this code:
- // get value for child[3] attributes[1]
- String attValue = children[3].getAttribute(attributes[1]);
- println("attValue: " + attValue);
Console shows:
attValue: translate(-8.5714245,593.94476)
Add this code:
- children[3].setAttribute(attributes[1],“translate(0,0)”);
Questions:
Is this the correct syntax?
I know setAttribute() is not included in proXML.
But "proXML allows you to easily integrate and manipulate this data in Processing."
What manipulation is it able to do?
If proXML cannot do this, is there another library that can?