Saving a graph in XML saves the structure of the graph. The graph element contains elements for all of the components in the graph. Attributes store property values for the graph and for its components.
You can save the values of all of the properties of the graph and its components, or you can save only those values that are different from the default property values.
You can restore the graph by applying the XML to a new graph. You can reset all the property values to default values as you apply, so that the XML is applied to a default graph. Alternately, you can apply the XML to a graph that you have modified; this adds the property values from the XML to the property values that you have saved.
To save a graph in XML, you call one of the following methods of the graph:
public java.lang.String getXML(boolean allProperties) public void writeXML(java.io.OutputStream stream, boolean allProperties)
The more efficient way to save XML is to save the property values only of properties whose
values are not the default values. To do this, you pass false
as the
allProperties
argument. The following code example saves the graph efficiently.
The example assumes that you have a graph called myGraph
. The XML file is saved in
the current folder.
FileOutputStream filestream = new FileOutputStream("myGraph.xml"); //save only the properties that are not the defaults myGraph.writeXML(filestream, false);
The following example shows the XML that is written when you save only the property values
that are different from the default property values. In this XML graph, the
GraphType
property has been set to specify a pie graph, the title has had text and
formatting specified, and the title has been made visible.
<?xml version="1.0"?> <Graph version = "1.5.0.1" graphType = "PIE"> <Title text = "Sales" visible = "true"> <GraphFont name = "Serif" style = "FS_ITALIC"/> </Title> </Graph>
To save all of the property values in XML attributes, you pass true
to the
allProperties
argument, as shown in the following example. This example assumes
that you have a graph called myGraph
.
FileOutputStream filestream = new FileOutputStream("myGraph.xml"); //save all of the property values myGraph.writeXML(filestream, true);