You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Maria Teresa Paratore <ma...@isti.cnr.it> on 2004/01/21 18:04:25 UTC

Problems with setSVGDocument

Hi,
I have an RDF document that contains an "svg node", i.e. information 
suitable to be displayed on a JSVGCanvas:
I have developed an application that creates an empty SVGDocument, parses 
the RDF file, extracts the "svg node" from it and appends it to the 
SVGDocument.
The SVGDocument I obtain this way is correct, but when I call 
JSVGCanvas.setSVGDocument(svgDoc) it is not displayed.
(NB: I set my JSVGcanvas ALWAYS DYNAMIC)


Here is a fragment of my code:
	   	public  void showSvg(){
        JSVGCanvas svgCanvas;
	  	 parserDom = new DOMParser();
	   	 DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
	   	SVGDOMImplementation svgImpl = (SVGDOMImplementation) 
SVGDOMImplementation.getDOMImplementation();
		String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
		
	             ........

	   	try{
	   		parserDom.parse(fileRDF.toURL().toString());
	   		doc = parserDom.getDocument();

	   		}
	   		catch(SAXException e){
	   			System.out.println("The file is not well formed");
	   		}
	   		catch(IOException e){
	   			System.out.println("errore di IO nella lettura del file rdf");
	   			}
	   	
	   		
		tempDoc = impl.createDocument(svgNS,"svg",null);
		
	//***parse the RDF***
		
	        DocumentTraversal trav = (DocumentTraversal)doc;
			NodeIterator ni = trav.createNodeIterator(
			doc.getDocumentElement(),
			NodeFilter.SHOW_ELEMENT,
			this,
			true);
			
		    dummyRoot = tempDoc.getDocumentElement();
		
      		while(((node = ni.nextNode())!= null)){
				Node importedNode = tempDoc.importNode(node, true);	
				dummyRoot.appendChild(importedNode);
				System.out.println("ho fatto l'append!!!");		        	
				  }
				  	svgDoc = (SVGDocument)tempDoc;
				
		      	svgCanvas.setDocument(svgDoc);  //this doesn't work
		

            /////*******Nodes Filtering*******/////////	
	             public short acceptNode(Node node){
			   	 if(node.getNodeName().equals("g"))
		   	 	return FILTER_ACCEPT;
				else return FILTER_SKIP;
    		       	}
    		   }


Here is the rdf document:
<?xml version="1.0" encoding="UTF-8"?>
<web:RDF xmlns:web="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns="http://www.w3.org/2000/svg"
         xmlns:comed="schema#" >

<Record web:about="radiografia-1" comed:name="documentoanalisi.doc">
  <comed:content>
     <svg width="475" height="387" xmlns:xlink="http://www.w3.org/1999/xlink" >
     <g visibility ="visible" id="xray">
     <image x="0" y="0" width="475" height="387" xlink:href="xray.jpg"/>
     </g>
     </svg>
  </comed:content>
   <comed:comments>
       <comed:note web:about="commento-1_2" comed:name="Dr. Livingstone"/>
       <comed:note web:about="commento-1_1" comed:name="Dr. Stranamore"/>
   </comed:comments>
</Record>

</web:RDF>




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


Re: Problems with setSVGDocument

Posted by Thomas DeWeese <Th...@Kodak.com>.
Maria Teresa Paratore wrote:

> Hi Bibek and thank you for answering,
> 
> actually, when I sent my previous email, the generated svg simply didn't 
> appear on the canvas, but soon after I fixed some errors in my code and the 
> "broken-image icon" appeared (with no errors generated).

    You should be able to place your mouse over the 'i' in circle
and have a 'tool tip' pop-up with some explanation of the the error
encountered.

> Now, I have changed my code according to your advice, but nothing new 
> seems to happen:
> still the same icon on the canvas...
> 
> There is probably some other issue I am missing?...

    Well the most common source of problems like this is
namespace stuff.  So I would make sure that the image element
has all it's attributes set properly (in particular that the
xlink:href is in the proper xlink namespace).

> Ciao,
> Maria Teresa
> 
> 
> At 03:04 PM 1/21/2004 -0600, you wrote:
> 
>> Hello,
>>
>> When you say "// this doesn't work", do you mean it just doesn't display,
>> or that it generates an error?
>>
>> Assuming it just doesn't display: you probably need to set the base 
>> URL for
>> the document, in order for Batik to know where to load xray.jpg from:
>>
>>         tempDoc = (SVGOMDocument) impl.createDocument(svgNS,"svg",null);
>>         tempDoc.setURLObject(rdfURI);
>>
>> Note that for non-href items (e.g., if you just had a 'rect' in 
>> there), it
>> should still show up.  If it doesn't, there's likely some other 
>> problem...
>> but your example RDF just has one 'image' item inside of it. (Which I 
>> would
>> think would show a broken-image icon, but... *shrug*)
>>
>>
>> If Batik is generating an error, what is that error?
>>
>>
>> Ciao,
>> Bibek
>>
>>
>>
>>
>> On Wed, 21 Jan 2004, Maria Teresa Paratore wrote:
>>
>> > Hi,
>> > I have an RDF document that contains an "svg node", i.e. information
>> > suitable to be displayed on a JSVGCanvas:
>> > I have developed an application that creates an empty SVGDocument, 
>> parses
>> > the RDF file, extracts the "svg node" from it and appends it to the
>> > SVGDocument.
>> > The SVGDocument I obtain this way is correct, but when I call
>> > JSVGCanvas.setSVGDocument(svgDoc) it is not displayed.
>> > (NB: I set my JSVGcanvas ALWAYS DYNAMIC)
>> >
>> >
>> > Here is a fragment of my code:
>> >               public  void showSvg(){
>> >         JSVGCanvas svgCanvas;
>> >               parserDom = new DOMParser();
>> >               DOMImplementation impl = 
>> SVGDOMImplementation.getDOMImplementation();
>> >               SVGDOMImplementation svgImpl = (SVGDOMImplementation)
>> > SVGDOMImplementation.getDOMImplementation();
>> >               String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>> >
>> >                    ........
>> >
>> >               try{
>> >                       parserDom.parse(fileRDF.toURL().toString());
>> >                       doc = parserDom.getDocument();
>> >
>> >                       }
>> >                       catch(SAXException e){
>> >                               System.out.println("The file is not 
>> well formed");
>> >                       }
>> >                       catch(IOException e){
>> >                               System.out.println("errore di IO nella 
>> lettura del file rdf");
>> >                               }
>> >
>> >
>> >               tempDoc = impl.createDocument(svgNS,"svg",null);
>> >
>> >       //***parse the RDF***
>> >
>> >               DocumentTraversal trav = (DocumentTraversal)doc;
>> >                       NodeIterator ni = trav.createNodeIterator(
>> >                       doc.getDocumentElement(),
>> >                       NodeFilter.SHOW_ELEMENT,
>> >                       this,
>> >                       true);
>> >
>> >                   dummyRoot = tempDoc.getDocumentElement();
>> >
>> >                       while(((node = ni.nextNode())!= null)){
>> >                               Node importedNode = 
>> tempDoc.importNode(node, true);
>> >                               dummyRoot.appendChild(importedNode);
>> >                               System.out.println("ho fatto 
>> l'append!!!");
>> >                                 }
>> >                                       svgDoc = (SVGDocument)tempDoc;
>> >
>> >                       svgCanvas.setDocument(svgDoc);  //this doesn't 
>> work
>> >
>> >
>> >             /////*******Nodes Filtering*******/////////
>> >                    public short acceptNode(Node node){
>> >                               if(node.getNodeName().equals("g"))
>> >                               return FILTER_ACCEPT;
>> >                               else return FILTER_SKIP;
>> >                       }
>> >                  }
>> >
>> >
>> > Here is the rdf document:
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <web:RDF xmlns:web="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>> >          xmlns="http://www.w3.org/2000/svg"
>> >          xmlns:comed="schema#" >
>> >
>> > <Record web:about="radiografia-1" comed:name="documentoanalisi.doc">
>> >   <comed:content>
>> >      <svg width="475" height="387" 
>> xmlns:xlink="http://www.w3.org/1999/xlink" >
>> >      <g visibility ="visible" id="xray">
>> >      <image x="0" y="0" width="475" height="387" 
>> xlink:href="xray.jpg"/>
>> >      </g>
>> >      </svg>
>> >   </comed:content>
>> >    <comed:comments>
>> >        <comed:note web:about="commento-1_2" comed:name="Dr. 
>> Livingstone"/>
>> >        <comed:note web:about="commento-1_1" comed:name="Dr. 
>> Stranamore"/>
>> >    </comed:comments>
>> > </Record>
>> >
>> > </web:RDF>
>> >
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>> > For additional commands, e-mail: batik-users-help@xml.apache.org
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 




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


Re: Problems with setSVGDocument

Posted by Maria Teresa Paratore <ma...@isti.cnr.it>.
Hi Bibek and thank you for answering,

actually, when I sent my previous email, the generated svg simply didn't appear
on the canvas, but soon after I fixed some errors in my code and the 
"broken-image icon"
appeared (with no errors generated).
Now, I have changed my code according to your advice, but nothing new seems 
to happen:
still the same icon on the canvas...

There is probably some other issue I am missing?...

Ciao,
Maria Teresa


At 03:04 PM 1/21/2004 -0600, you wrote:

>Hello,
>
>When you say "// this doesn't work", do you mean it just doesn't display,
>or that it generates an error?
>
>Assuming it just doesn't display: you probably need to set the base URL for
>the document, in order for Batik to know where to load xray.jpg from:
>
>         tempDoc = (SVGOMDocument) impl.createDocument(svgNS,"svg",null);
>         tempDoc.setURLObject(rdfURI);
>
>Note that for non-href items (e.g., if you just had a 'rect' in there), it
>should still show up.  If it doesn't, there's likely some other problem...
>but your example RDF just has one 'image' item inside of it. (Which I would
>think would show a broken-image icon, but... *shrug*)
>
>
>If Batik is generating an error, what is that error?
>
>
>Ciao,
>Bibek
>
>
>
>
>On Wed, 21 Jan 2004, Maria Teresa Paratore wrote:
>
> > Hi,
> > I have an RDF document that contains an "svg node", i.e. information
> > suitable to be displayed on a JSVGCanvas:
> > I have developed an application that creates an empty SVGDocument, parses
> > the RDF file, extracts the "svg node" from it and appends it to the
> > SVGDocument.
> > The SVGDocument I obtain this way is correct, but when I call
> > JSVGCanvas.setSVGDocument(svgDoc) it is not displayed.
> > (NB: I set my JSVGcanvas ALWAYS DYNAMIC)
> >
> >
> > Here is a fragment of my code:
> >               public  void showSvg(){
> >         JSVGCanvas svgCanvas;
> >               parserDom = new DOMParser();
> >               DOMImplementation impl = 
> SVGDOMImplementation.getDOMImplementation();
> >               SVGDOMImplementation svgImpl = (SVGDOMImplementation)
> > SVGDOMImplementation.getDOMImplementation();
> >               String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >
> >                    ........
> >
> >               try{
> >                       parserDom.parse(fileRDF.toURL().toString());
> >                       doc = parserDom.getDocument();
> >
> >                       }
> >                       catch(SAXException e){
> >                               System.out.println("The file is not well 
> formed");
> >                       }
> >                       catch(IOException e){
> >                               System.out.println("errore di IO nella 
> lettura del file rdf");
> >                               }
> >
> >
> >               tempDoc = impl.createDocument(svgNS,"svg",null);
> >
> >       //***parse the RDF***
> >
> >               DocumentTraversal trav = (DocumentTraversal)doc;
> >                       NodeIterator ni = trav.createNodeIterator(
> >                       doc.getDocumentElement(),
> >                       NodeFilter.SHOW_ELEMENT,
> >                       this,
> >                       true);
> >
> >                   dummyRoot = tempDoc.getDocumentElement();
> >
> >                       while(((node = ni.nextNode())!= null)){
> >                               Node importedNode = 
> tempDoc.importNode(node, true);
> >                               dummyRoot.appendChild(importedNode);
> >                               System.out.println("ho fatto l'append!!!");
> >                                 }
> >                                       svgDoc = (SVGDocument)tempDoc;
> >
> >                       svgCanvas.setDocument(svgDoc);  //this doesn't work
> >
> >
> >             /////*******Nodes Filtering*******/////////
> >                    public short acceptNode(Node node){
> >                               if(node.getNodeName().equals("g"))
> >                               return FILTER_ACCEPT;
> >                               else return FILTER_SKIP;
> >                       }
> >                  }
> >
> >
> > Here is the rdf document:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <web:RDF xmlns:web="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> >          xmlns="http://www.w3.org/2000/svg"
> >          xmlns:comed="schema#" >
> >
> > <Record web:about="radiografia-1" comed:name="documentoanalisi.doc">
> >   <comed:content>
> >      <svg width="475" height="387" 
> xmlns:xlink="http://www.w3.org/1999/xlink" >
> >      <g visibility ="visible" id="xray">
> >      <image x="0" y="0" width="475" height="387" xlink:href="xray.jpg"/>
> >      </g>
> >      </svg>
> >   </comed:content>
> >    <comed:comments>
> >        <comed:note web:about="commento-1_2" comed:name="Dr. Livingstone"/>
> >        <comed:note web:about="commento-1_1" comed:name="Dr. Stranamore"/>
> >    </comed:comments>
> > </Record>
> >
> > </web:RDF>
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: batik-users-help@xml.apache.org



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


Re: Problems with setSVGDocument

Posted by Bibek Sahu <sc...@dodds.net>.
Hello,

When you say "// this doesn't work", do you mean it just doesn't display,
or that it generates an error?

Assuming it just doesn't display: you probably need to set the base URL for
the document, in order for Batik to know where to load xray.jpg from:

	tempDoc = (SVGOMDocument) impl.createDocument(svgNS,"svg",null);
	tempDoc.setURLObject(rdfURI);

Note that for non-href items (e.g., if you just had a 'rect' in there), it
should still show up.  If it doesn't, there's likely some other problem...
but your example RDF just has one 'image' item inside of it. (Which I would
think would show a broken-image icon, but... *shrug*)


If Batik is generating an error, what is that error?


Ciao,
Bibek




On Wed, 21 Jan 2004, Maria Teresa Paratore wrote:

> Hi,
> I have an RDF document that contains an "svg node", i.e. information
> suitable to be displayed on a JSVGCanvas:
> I have developed an application that creates an empty SVGDocument, parses
> the RDF file, extracts the "svg node" from it and appends it to the
> SVGDocument.
> The SVGDocument I obtain this way is correct, but when I call
> JSVGCanvas.setSVGDocument(svgDoc) it is not displayed.
> (NB: I set my JSVGcanvas ALWAYS DYNAMIC)
>
>
> Here is a fragment of my code:
> 	   	public  void showSvg(){
>         JSVGCanvas svgCanvas;
> 	  	 parserDom = new DOMParser();
> 	   	 DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
> 	   	SVGDOMImplementation svgImpl = (SVGDOMImplementation)
> SVGDOMImplementation.getDOMImplementation();
> 		String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>
> 	             ........
>
> 	   	try{
> 	   		parserDom.parse(fileRDF.toURL().toString());
> 	   		doc = parserDom.getDocument();
>
> 	   		}
> 	   		catch(SAXException e){
> 	   			System.out.println("The file is not well formed");
> 	   		}
> 	   		catch(IOException e){
> 	   			System.out.println("errore di IO nella lettura del file rdf");
> 	   			}
>
>
> 		tempDoc = impl.createDocument(svgNS,"svg",null);
>
> 	//***parse the RDF***
>
> 	        DocumentTraversal trav = (DocumentTraversal)doc;
> 			NodeIterator ni = trav.createNodeIterator(
> 			doc.getDocumentElement(),
> 			NodeFilter.SHOW_ELEMENT,
> 			this,
> 			true);
>
> 		    dummyRoot = tempDoc.getDocumentElement();
>
>       		while(((node = ni.nextNode())!= null)){
> 				Node importedNode = tempDoc.importNode(node, true);
> 				dummyRoot.appendChild(importedNode);
> 				System.out.println("ho fatto l'append!!!");
> 				  }
> 				  	svgDoc = (SVGDocument)tempDoc;
>
> 		      	svgCanvas.setDocument(svgDoc);  //this doesn't work
>
>
>             /////*******Nodes Filtering*******/////////
> 	             public short acceptNode(Node node){
> 			   	 if(node.getNodeName().equals("g"))
> 		   	 	return FILTER_ACCEPT;
> 				else return FILTER_SKIP;
>     		       	}
>     		   }
>
>
> Here is the rdf document:
> <?xml version="1.0" encoding="UTF-8"?>
> <web:RDF xmlns:web="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>          xmlns="http://www.w3.org/2000/svg"
>          xmlns:comed="schema#" >
>
> <Record web:about="radiografia-1" comed:name="documentoanalisi.doc">
>   <comed:content>
>      <svg width="475" height="387" xmlns:xlink="http://www.w3.org/1999/xlink" >
>      <g visibility ="visible" id="xray">
>      <image x="0" y="0" width="475" height="387" xlink:href="xray.jpg"/>
>      </g>
>      </svg>
>   </comed:content>
>    <comed:comments>
>        <comed:note web:about="commento-1_2" comed:name="Dr. Livingstone"/>
>        <comed:note web:about="commento-1_1" comed:name="Dr. Stranamore"/>
>    </comed:comments>
> </Record>
>
> </web:RDF>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>


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