On Feb 12, 2008 10:01 AM, jeremie_76 <[EMAIL PROTECTED]> wrote: > >> I have SVG documents with references to another SVG documents (using > use) > >> and I would like to dynamically change attributes in the externals SVG > >> documents. > >> > >> When I load the top level svg document, I get the DOM representation of > >> it but I only have a reference to a use Element. So is it possible with > >> this use Element to dynamically modify the objects attributes in the > use > >> document (like the fill of a rectangle) ? > >> > > From my experience, this isn't possible. I'm not a Batik developer or > > anything, but I've used it for months now and looked for a feature like > > this, but never found one. I don't think use elements can be modified, > but > > there are alternatives if you want to put one SVG document inside > another. > > > > The easiest way to put one SVG document inside another is to load each > as > > a separate SVGDocument object inside your Batik program, and then import > > the node from one document into another, like this: > > > > doc1.getRootElement().appendChild(doc1.importNode(doc2.getElementById > ("someObject"))); > > > > When you do this, the external document becomes a part of the DOM tree > and > > can be modified like any other element. > > First of all, thank you for your help. > I think you're right, in my research I've not found any information who > let > me think that it's possible. > So your idea could be a solution, but it imposes to review with a new > algorithm how the unique "id" of each element could be treated. I can have > two different elements in two different svg documents with the same "id" > and > I must be able to find the good one (the element I want to modify) in > function of the original embed "use" document when an attribute change is > needed. > > We have implemented code to "inline" one SVG document into another like this. It's a bit tricky...
1. You must uniquify all XML id's in the imported document (e.g., give them all a random prefix unlikely to collide). 2. All attributes in the imported document that contain relative URIs must be re-relativized based on the base URI of the importing document (or xml:base inherited at the import point). E.g., "fill", "filter", "stroke", "xlink:href", etc. Note that #1 and #2 are inter-related, because XML id's can appear as fragment identifiers in URIs, so the remappings have to be done in coordination. Doing this was good enough for our use cases; however our code is still incomplete, e.g., it doesn't handle Xpointer<http://www.w3.org/TR/xptr-framework/>references. -Archie -- Archie L. Cobbs