Hi Prad, prad <[EMAIL PROTECTED]> wrote on 08/23/2006 01:47:47 AM:
> Idea is good..I tried it out.Am getting one problem ie after replacing new > element with different namespace and serialize the dom to xml....new xml > file is taking the global namespace ie"http://www.w3.org/2000/svg" instead > of "http://myNameSpace.org"......Any idea about where i might be wrong You need to declare and use a new namespace prefix for the element. String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/"; // Declare the new namespace prefix (for serialization) Element root = doc.getRootElement(); root.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:myNS", newNamespace); // Use the new namespace prefix in the document. Element newElem = doc.createElementNS(newNamespace, "myNS:"+problem.getLocalName()); > thomas.deweese wrote: > > > > Hi Prad, > > > > Do not send the same message multiple times to the list. > > > > prad <[EMAIL PROTECTED]> wrote on 08/22/2006 03:20:03 AM: > > > >> Now i have decided to parse svg file as simple xml dom and change the > >> namespace of few elements and then use this modified file to create > >> SVGDOM.......does it works....if yes, > > > > Yes, this will work. Since you are supposed to ignore the > > elements you could also remove them (this is simpler). > > > >> how do i change or move elements to different namespace... > > > > I would suggest using the following to locate the problem elements: > > Element.getElementsByTagNameNS(String namespace, String tagName) > > > > Then the simplest thing to do is remove them from the DOM: > > > > Element problem = nodeList.get(i); > > problem.getParentNode().removeChild(problem); > > > > Moving them to another namespace is a little tricker. First > > you need to create a new element in the new namespace: > > > > Element newElem = doc.createElementNS(newNamespace, > > problem.getTagName()); > > // Then copy the attributes from the problem node to the new node. > > NamedNodeMap nnm = problem.getAttributes(); > > int len = nnm.getLength(); > > for (int i=0; i<len; i++) { > > Attr a = (Attr)nnm.get(i); > > Attr newAttr = (Attr)doc.importNode(a, true); > > newElem.setAttributeNode(newAttr); > > } > > > > Then you need to replace the problem element with the > > new Element: > > > > problem.getParentNode().replaceChild(newElem, problem); > > > > This get's a bit more complex if the elements that need to > > be moved may have children that also need to be moved... You basically > > need to walk the problem element's children running the above code > > on each of them an appending them to 'newElem'. > > > > (The above is untested 'psuedo code') > > Good luck! > > > >> thomas.deweese wrote: > >> > > >> > Hi Prad, > >> > > >> > prad <[EMAIL PROTECTED]> wrote on 08/18/2006 02:15:56 AM: > >> > > >> >> Thanks for the suggestion,but am not supposed to change svg file or > >> > change > >> >> namespace wat i have to do is to handle such elements by ignoring > > them > >> > > >> > I will _very_ strong recommend that you fix the files. > >> > Changing tools to work around broken files is 100% always the > >> > wrong answer to the problem. > >> > > >> > That said you can try creating a subclass of > >> > batik.dom.svg.SVGDOMImplementation that replaces the > >> > createElement & createElementNS methods. > >> > > >> > This is about all the help I'll give on this topic > >> > as I consider this the totally wrong way to approach > >> > the problem. > >> > > >> > Good luck! > >> > > >> >> thomas.deweese wrote: > >> >> > > >> >> > Hi Prad, > >> >> > > >> >> > prad <[EMAIL PROTECTED]> wrote on 08/17/2006 06:06:13 AM: > >> >> > > >> >> >> Am finding difficult to get the dom for a svg file. > >> >> > > >> >> > Actually it looks like you are getting DOM fine for > >> >> > SVG files. It is files that look a little like an > >> >> > SVG file but aren't that causing you problems (as they should). > >> >> > > >> >> >> But If the svg file contains other tags like > >> >> > > >> >> > This is not a valid SVG file: > >> >> >> <svg> > >> >> >> <segments> > >> >> >> </segments> > >> >> > > >> >> > I suggest you fix it by moving the non-SVG elements > >> >> > out of the SVG namespace: > >> >> > <svg xmlns:prad="http://prad.org/"> > >> >> > <prad:segments> > >> >> > </prad:segments> > >> >> > </svg> > >> >> > > >> >> > > >> >> > > > --------------------------------------------------------------------- > >> >> > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > >> >> > For additional commands, e-mail: > >> > [EMAIL PROTECTED] > >> >> > > >> >> > > >> >> > > >> >> > >> >> -- > >> >> View this message in context: > >> > http://www.nabble.com/getting-dom-from-svg-file- > >> >> tf2120596.html#a5860806 > >> >> Sent from the Batik - Users forum at Nabble.com. > >> >> > >> >> > >> >> --------------------------------------------------------------------- > >> >> To unsubscribe, e-mail: > > [EMAIL PROTECTED] > >> >> For additional commands, e-mail: > > [EMAIL PROTECTED] > >> >> > >> > > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > >> > For additional commands, e-mail: > > [EMAIL PROTECTED] > >> > > >> > > >> > > >> > >> -- > >> View this message in context: > > http://www.nabble.com/getting-dom-from-svg-file- > >> tf2120596.html#a5920621 > >> Sent from the Batik - Users forum at Nabble.com. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > View this message in context: http://www.nabble.com/getting-dom-from-svg-file- > tf2120596.html#a5938589 > Sent from the Batik - Users forum at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
