Loading...
Logo
Processing Forum
Is there a (maybe undocumented?) way to directly access/manipulate the attributes of SVG elements?

The visualization I'm working on utilizes many custom cursors, and it makes the most sense to me to embed offsets (that put the right part of the cursor at the center) in the SVG itself. This is a really simple example, but there are many other attributes that I'd like to be able to access or manipulate for my project.

I've played with the Geomerative package, but I don't see a way to get to the attributes directly there either. I might be able to get it to work with Batik, but that seems a little overkill just to get at the attributes of elements.

Replies(6)

No, PShapeSVG just discards the attributes it doesn't understand.
But of course, you can open the file with loadShape(), and again with new XMLElement(), then navigate to your element and read its attribute.
Thanks for the quick response! Do you know if there would be a way to access the attributes that it did keep - for example, if I wanted to know the x-coordinate of a rectangle?
There was a recent thread on this topic... Search the forum and/or look at the JavaDoc of PShape.
I did both before asking this question (although it's very possible I missed the thread you're referring to ): I guess what I'm really asking whether it is possible to access or manipulate PShapeSVG element attributes in a similar way to manipulating the DOM with javascript?
Curiously, I couldn't find back the thread with Zoho's search, while the search (powered by Google...) from Processing.org worked well... (I searched pshape params, I had the advantage to know what to search!)
https://forum.processing.org/topic/pshape-coordinates
https://forum.processing.org/topic/interrogating-lines-within-a-loaded-svg
and searching pshape rectangle, I found back the thread I was thinking of:
https://forum.processing.org/topic/resizing-pshape-objects-with-getchild

Overall, indeed, not obvious to search! Sorry for the lazy answer (but I have to be terse, sometime, trying to answer many questions in the forum).

Note: if you are brave enough, a good source of information is the source code of PShape and PShapeSVG themselves...
Hey, no worries - thanks for answering at all! You've really helped a lot.