You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Keiron Liddle <ke...@aftexsw.com> on 2001/10/30 10:30:15 UTC

importing dom

Hi,

I have some svg content embedded inside an xml document. I am reading
through the dom and when I find the svg I am trying to convert it into an
svg document.

The svg xml is identified with an xmlns="...".

If I create a new generic document then import the svg node and add it as
the root document node. I have the equivalent of the svg document I want.
Then to convert it into a batik svg document I try to use
DOMUtilities.deepCloneDocument(...)
this only gives back a document with a generic root element (which will
cause an npe if I try to get the root document element). The problem is
that the node.getNamespaceURI() returns null for my intermediate document.

If I copy the deepCloneDocument method and give it the correct namespace it
still cannot work (as the child nodes also have a null namespace I presume)
as the attributes are not copied across.
The new document has a bunch of new attributes on the root svg element and
also has the xmlns="<svg namespace>" repeated, I believe one has the null
namespace and the other has the xmlns namespace

I get the following exception when I attempt to import the root node of the
document into yet another svg document.

java.lang.NullPointerException
	at org.apache.batik.dom.AbstractElement.fireDOMAttrModifiedEvent(AbstractElement.java:486)
	at org.apache.batik.dom.AbstractElement$NamedNodeHashMap.setNamedItem(AbstractElement.java:677)
	at org.apache.batik.dom.AbstractElement$NamedNodeHashMap.setNamedItemNS(AbstractElement.java:625)
	at org.apache.batik.dom.AbstractElement.setAttributeNode(AbstractElement.java:168)
	at org.apache.batik.dom.AbstractElement.copyInto(AbstractElement.java:407)
	at org.apache.batik.dom.svg.SVGOMElement.copyInto(SVGOMElement.java:203)
	at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:275)
	at org.apache.batik.dom.AbstractDocument.importNode(AbstractDocument.java:211)


Does anyone know if there is a way to handle this.
I just want to get a batik dom svg document that is the equivalent of the
svg that is embedded in the original document.
I cannot create an svg document and then add or replace the root element as
batik won't let me.

Thanks
Keiron.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: importing dom

Posted by Stephane Hillion <sh...@ilog.fr>.
On Wednesday 31 October 2001 15:08, Keiron Liddle wrote:
> On 2001.10.31 13:34 Stephane Hillion wrote:
> > > From what you said it sounds like it is not possible and batik won't
> >
> > let me
> >
> > > do it.
> > > I could not repeat the npe, it must be a combination of a number of
> > > factors.
>
> I found out that the npe occurs when I serialize the document to an object
> stream and then read it back.
> I have attached the code that displays the two problems.

It seems to be a bug in Batik. The Java serialization of the DOM does not 
work. You can post a bug in Bugzilla.
Thanks
--
  Stephane.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: importing dom

Posted by Keiron Liddle <ke...@aftexsw.com>.
On 2001.10.31 13:34 Stephane Hillion wrote:
> > From what you said it sounds like it is not possible and batik won't
> let me
> > do it.
> > I could not repeat the npe, it must be a combination of a number of
> > factors.

I found out that the npe occurs when I serialize the document to an object
stream and then read it back.
I have attached the code that displays the two problems.

Re: importing dom

Posted by Keiron Liddle <ke...@aftexsw.com>.
Thanks, that helps, it appears to import the document elements properly,
but I am still not getting the attributes on the child elements

For example I just get the following svg node when imported
<svg contentScriptType="" width="20" zoomAndPan="" contentStyleType=""
height="20" preserveAspectRatio="" xmlns="http://www.w3.org/2000/svg"
version="">
  <g>
     <rect/>
     <rect/>
  </g>
</svg>

The g and both rect's shold have attributes on them.

On 2001.10.31 13:34 Stephane Hillion wrote:
> All your troubles comes from the fact that the DocumentBuilder instances
> you 
> use are not namespace aware. So just configure a DocumentBuilderFactory
> by 
> calling its setNamespaceAware() method and the DocumentBuilder objects 
> created will build correct DOM level 2 trees.
> --
>   Stephane.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: importing dom

Posted by Stephane Hillion <sh...@ilog.fr>.
On Wednesday 31 October 2001 10:57, Keiron Liddle wrote:
> On 2001.10.30 16:41 Stephane Hillion wrote:
> > It is difficult to help you without some examples or pieces of code.
> > But what you must have in mind is that the xmlns attribute and prefix is
> > used
> > by XML parsers to bind elements to namespaces, and once you are in the
> > DOM
> > world it is not used anymore.
> > To make the importation work, you must be sure that all the elements of
> > the
> > SVG fragment were in the SVG namespace at creation time.
>
> I have attached some code and an example svg file. This should indicate
> what I am trying to do.
> Note the xmlns attribute is repeated on some of the svg elements.
>
> So how do I make sure that all the elements are in the svg namespace at
> creation time, the example (I would have thought) does this but the
> namespace uri of the elements is still null. (I am using xalan 2.2d11
> xerces 1.4.3 and current cvs batik)
>
> From what you said it sounds like it is not possible and batik won't let me
> do it.
> I could not repeat the npe, it must be a combination of a number of
> factors.

All your troubles comes from the fact that the DocumentBuilder instances you 
use are not namespace aware. So just configure a DocumentBuilderFactory by 
calling its setNamespaceAware() method and the DocumentBuilder objects 
created will build correct DOM level 2 trees.
--
  Stephane.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: importing dom

Posted by Keiron Liddle <ke...@aftexsw.com>.
On 2001.10.30 16:41 Stephane Hillion wrote:
> 
> It is difficult to help you without some examples or pieces of code.
> But what you must have in mind is that the xmlns attribute and prefix is
> used 
> by XML parsers to bind elements to namespaces, and once you are in the
> DOM 
> world it is not used anymore.
> To make the importation work, you must be sure that all the elements of
> the 
> SVG fragment were in the SVG namespace at creation time.

I have attached some code and an example svg file. This should indicate
what I am trying to do.
Note the xmlns attribute is repeated on some of the svg elements.

So how do I make sure that all the elements are in the svg namespace at
creation time, the example (I would have thought) does this but the
namespace uri of the elements is still null. (I am using xalan 2.2d11
xerces 1.4.3 and current cvs batik)

>From what you said it sounds like it is not possible and batik won't let me
do it.
I could not repeat the npe, it must be a combination of a number of
factors.



Re: importing dom

Posted by Stephane Hillion <sh...@ilog.fr>.
On Tuesday 30 October 2001 10:30, Keiron Liddle wrote:
> Hi,
>
> I have some svg content embedded inside an xml document. I am reading
> through the dom and when I find the svg I am trying to convert it into an
> svg document.
>
> The svg xml is identified with an xmlns="...".
>
> If I create a new generic document then import the svg node and add it as
> the root document node. I have the equivalent of the svg document I want.
> Then to convert it into a batik svg document I try to use
> DOMUtilities.deepCloneDocument(...)
> this only gives back a document with a generic root element (which will
> cause an npe if I try to get the root document element). The problem is
> that the node.getNamespaceURI() returns null for my intermediate document.
>
> If I copy the deepCloneDocument method and give it the correct namespace it
> still cannot work (as the child nodes also have a null namespace I presume)
> as the attributes are not copied across.
> The new document has a bunch of new attributes on the root svg element and
> also has the xmlns="<svg namespace>" repeated, I believe one has the null
> namespace and the other has the xmlns namespace
>
> I get the following exception when I attempt to import the root node of the
> document into yet another svg document.
>
> java.lang.NullPointerException
> 	at
> org.apache.batik.dom.AbstractElement.fireDOMAttrModifiedEvent(AbstractEleme
>nt.java:486) at
> org.apache.batik.dom.AbstractElement$NamedNodeHashMap.setNamedItem(Abstract
>Element.java:677) at
> org.apache.batik.dom.AbstractElement$NamedNodeHashMap.setNamedItemNS(Abstra
>ctElement.java:625) at
> org.apache.batik.dom.AbstractElement.setAttributeNode(AbstractElement.java:
>168) at
> org.apache.batik.dom.AbstractElement.copyInto(AbstractElement.java:407) at
> org.apache.batik.dom.svg.SVGOMElement.copyInto(SVGOMElement.java:203) at
> org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:275) at
> org.apache.batik.dom.AbstractDocument.importNode(AbstractDocument.java:211)
>
>
> Does anyone know if there is a way to handle this.
> I just want to get a batik dom svg document that is the equivalent of the
> svg that is embedded in the original document.
> I cannot create an svg document and then add or replace the root element as
> batik won't let me.

It is difficult to help you without some examples or pieces of code.
But what you must have in mind is that the xmlns attribute and prefix is used 
by XML parsers to bind elements to namespaces, and once you are in the DOM 
world it is not used anymore.
To make the importation work, you must be sure that all the elements of the 
SVG fragment were in the SVG namespace at creation time.

>
> Thanks
> Keiron.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org