Reading XML/SVG file

I want to display a diagram saved as xml/svg

To save the xml.svg I do the following

<BR> FileOutputStream fos = new FileOutputStream(fileName);<BR> <BR> // generate the JGo xml and svg for output<BR> DefaultDocument svgDomDoc = new DefaultDocument();<BR> svgDomDoc.setGenerateJGoXML(true);<BR> svgDomDoc.setGenerateSVG(true);<BR> svgDomDoc.SVGWriteDoc(fos, _myJGoView.getDocument());<BR> <BR> fos.flush();<BR> fos.close();<BR>

And i get a file like this

[code]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>


<jgoxml:JGoClass class=“com.nwoods.jgo.JGoDocument” defaultlayer=“null” docheight=“603” docleft=“0” doctop=“0” docwidth=“1385” modifiable=“true”/>


<jgoxml:JGoClass class=“com.nwoods.jgo.JGoLayer” modifiable=“true” transparency=“1.0” visible=“true”/>

<jgoxml:JGoClass backdraw=“jgoid1” bottomport=“jgoid3” class=“com.nwoods.jgo.examples.MultiTextNode” embeddedlinepen=“true” insetbottom=“0” insetleft=“2” insetright=“2”

insettop="0" itemwidth="200" leftports="jgoid7 jgoid8 jgoid9" linepen="jgoid13" rightports="jgoid10 jgoid11 jgoid12" spacing="0" topport="jgoid2" vectorelements="jgoid4 jgoid5 jgoid6">













... etc ...











[/code]

I then read the file with the code shown below. The file is read, the JGoDocument is not empty but the view is empty.

[code]
FileInputStream fis = new FileInputStream(fileName);

// generate the JGo xml and svg for output
DefaultDocument svgDomDoc = new DefaultDocument();
JGoDocument jgoDocFromXml = new JGoDocument();
svgDomDoc.SVGReadDoc(fis, jgoDocFromXml);

fis.close();

_myJGoView.setDocument(jgoDocFromXml);
[/code]

What's wrong? I am expecting the diagram to be displayed in _myJGoView (which is displayed in an applet).

Your code looks like it should work.

The fact that you say there are JGoObjects in the JGoDocument but that they are not visible in the JGoView makes me suspicious that the problem may not be related to XML/SVG. Are you sure that _myJGoView is correctly displaying objects in your applet? Perhaps before calling _myJGoView.setDocument you could add a simple JGoBasicNode to the document originally associated with _myJGoView and verify that it is visible.
Assuming that works, you might want to take a look at the SampleApp example application and see how the save and restore functions differ from what you are doing. See if you can reproduce the problem with some simple changes to SampleApp. The SaveItem and OpenItem actions are very simple and very similar to your code above.

OK, I added a JGoBasicNode as follows
[code]
FileInputStream fis = new FileInputStream(fileName);

// generate the JGo xml and svg for output
DefaultDocument svgDomDoc = new DefaultDocument();
JGoDocument jgoDocFromXml = new JGoDocument();
svgDomDoc.SVGReadDoc(fis, jgoDocFromXml);

fis.close();
JGoBasicNode jgoBasicNode = new JGoBasicNode();
JGoText jgoText = new JGoText();
jgoText.setText(“Testing a JGoText entry inside a JGoBasicNode”);
jgoBasicNode.setLabel(jgoText);
jgoDocFromXml.addObjectAtTail(jgoBasicNode);
_myJGoView.setDocument(jgoDocFromXml);
System.out.println(“finished loadXml(), is_myJGoView empty?:”+_myJGoView.isEmpty()+

" _myJGoView.getDocument() is empty?:"+_myJGoView.getDocument().isEmpty());
[/code]
The result is that _myJGoView displays the JGoBasicNode and the System.out.printlin prints
[code]finished loadXml(), is_myJGoView empty?:true _myJGoView.getDocument() is empty?:false
[/code]
So ... I am still a little stumped ... any suggestions?

OK, so we know that your JGoView is capable of displaying JGoObjects. That’s a start.

The last line indicates that the JGoDocument is not empty and that the JGoView is empty, which is just what we should expect. Despite the fact that the JGoView is showing a JGoObject, the JGoView is indeed empty because there are no objects in the JGoView itself. They are all in the JGoDocument. If the GoBasicNode had been selected, there would have been a selection handle in the JGoView and in that case the isEmpty() would have returned false.
So the question remains, where are all the other objects defined by the XML?
I put together a small sample app that read a simple XML file produced by SampleApp, and then I copied your code to read the XML file:
FileInputStream fis = new FileInputStream("c://temp//sample.xml");
// generate the JGo xml and svg for output
DefaultDocument svgDomDoc = new DefaultDocument();
JGoDocument jgoDocFromXml = new JGoDocument();
svgDomDoc.SVGReadDoc(fis, jgoDocFromXml);
fis.close();
_myJGoView.setDocument(jgoDocFromXml);
System.out.println("finished loadXml(), is_myJGoView empty?:"+_myJGoView.isEmpty()+
" _myJGoView.getDocument() is empty?:"+_myJGoView.getDocument().isEmpty());
When I ran it, the simple graph I created in SampleApp appeared in the new JGoView. And of course, it still correctly said that the doc was not empty and the view was empty. If you'd like to try it yourself, I've uploaded sample.xml to the forum and you can download it from:
http://www.nwoods.com/forum/uploads/sample.xml
So we know that the code you are using to read the XML and display it in a JGoView works. About the only thing left is the contents of your XML file itself.
Can you reproduce the problem with a very small XML file? Preferably one that doesn't contain any proprietary subclasses?

[QUOTE=ssmith]OK, so we know that your JGoView is capable of displaying JGoObjects. That’s a start.

The last line indicates that the JGoDocument is not empty and that the JGoView is empty, which is just what we should expect. Despite the fact that the JGoView is showing a JGoObject, the JGoView is indeed empty because there are no objects in the JGoView itself. They are all in the JGoDocument. If the GoBasicNode had been selected, there would have been a selection handle in the JGoView and in that case the isEmpty() would have returned false.

So the question remains, where are all the other objects defined by the XML?

I put together a small sample app that read a simple XML file produced by SampleApp, and then I copied your code to read the XML file:

        FileInputStream fis = new FileInputStream("c://temp//sample.xml");
        // generate the JGo xml and svg for output
        DefaultDocument svgDomDoc = new DefaultDocument();
        JGoDocument jgoDocFromXml = new JGoDocument();
        svgDomDoc.SVGReadDoc(fis, jgoDocFromXml);
        fis.close();
        _myJGoView.setDocument(jgoDocFromXml);
        System.out.println("finished loadXml(), is_myJGoView empty?:"+_myJGoView.isEmpty()+
            " _myJGoView.getDocument() is empty?:"+_myJGoView.getDocument().isEmpty());

When I ran it, the simple graph I created in SampleApp appeared in the new JGoView. And of course, it still correctly said that the doc was not empty and the view was empty. If you’d like to try it yourself, I’ve uploaded sample.xml to the forum and you can download it from:

http://www.nwoods.com/forum/uploads/sample.xml

So we know that the code you are using to read the XML and display it in a JGoView works. About the only thing left is the contents of your XML file itself.

Can you reproduce the problem with a very small XML file? Preferably one that doesn’t contain any proprietary subclasses?

[/quote]
I can’t create the XML that the applet will be using without using proprietary classes, but I can include the class definitions needed and the xml produced too.

Is it possible that the function used to read the svg-xml would be giving me trouble because the proprietary classes use parameterised? constructors?

Yes, we are using the following code to create instances of your class:
Class elementClass = Class.forName(className);
obj = elementClass.newInstance();
So there needs to be a constructor with no parameters for us to initially create the instance.

Can I override the method that is instantiating the classes and if so what Class file and method is involved?

[QUOTE=ssmith]

Yes, we are using the following code to create instances of your class:

Class elementClass = Class.forName(className);

obj = elementClass.newInstance();

So there needs to be a constructor with no parameters for us to initially create the instance.

[/quote] Another question ...

If I set up getters and setters for the parameters that I would normally place in the constructor is JGo capable of discovering them and invoking them after it instantiates my classes using the parameterless constructor?

JGo constructs an empty class using the code above, and then the class properties are read from the XML and set in your override of the SVGReadObject method in your class.