Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Load from XML not working with latest version of JDiagram (Read 94 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 73
Joined: Jan 23rd, 2015
Load from XML not working with latest version of JDiagram
Sep 17th, 2026 at 6:59pm
Print Post  
We use 'save to XML' and 'load from XML' to keep diagram data in a database. This has worked fine for years.

It is now failing to read any Nodes from the XML, although looking at the XML string they can be seen.

Possible reasons I can think of for this:

  • We're currently using the Trial version of the software whilst our purchase of a licence is being processed.
  • Saved diagram has '<Diagram Version="16">' in the XML, but newly created diagrams have '<Diagram Version="18">' - so some things have changed in the XML the new version creates/expects
  • Some, but not all, of the nodes are custom nodes


Code used to read the XML for the diagram is attached.

Please could you tell me why 'load from XML' is currently failing?
  

LoadDiagramFromXMLCode.txt ( 1 KB | 7 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3518
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #1 - Sep 18th, 2026 at 4:21am
Print Post  
What are the parent types of you custom nodes?

Code
Select All
Diagram.registerItemClass( Custom1Node.class, "Custom1Node", 1 );
Diagram.registerItemClass( StyledTextComponent.class, "StyledTextComponent", 1 );
Diagram.registerItemClass( TitleNode.class, "TitleNode", 1 ); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3518
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #2 - Sep 18th, 2026 at 4:37am
Print Post  
Also what version are you migrating from (check manifest.txt in your old jar file)? I can see XML mentioned in version history, e.g. for v3:

Quote:
API changes
serializeTag and deserializeTag handlers should call the setHandled method in order for the control to use the custom tag xml.


Is there any exception logged here?

Code (Java)
Select All
      catch (SAXException | ParserConfigurationException | IOException | XmlException se)
      {
        logger.error( "Failed to load diagram from XML", se );
      } 



  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 73
Joined: Jan 23rd, 2015
Re: Load from XML not working with latest version of JDiagram
Reply #3 - Sep 18th, 2026 at 11:24am
Print Post  
TitleNode - parent is ShapeNode
StyledTextComponent - parent is TextComponent
Custom1Node - parent is CompositeNode

setHandled() is called within the serializeTag and deserializeTag methods.

No error is thrown but 'diagram.getNodes()' returns empty array.

Couldn't find version in Manifest - so have attached manifest file.

All files within the old Jar seem to be dated 2015-09-24 if that helps at all.
  

JDiagram-Old-MANIFEST.MF ( 0 KB | 2 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3518
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #4 - Sep 18th, 2026 at 12:34pm
Print Post  
By 'load from XML not working', do you mean you cannot load XML saved by old version, or it fails loading XML created by new version too?

That date places the jar build somewhere between our V4.1.3 and V4.1.4 releases, so either a pre-release build we might have uploaded as preview / beta version, or your company's custom version if you've ever built from source code.

https://mindfusion.dev/Forum/YaBB.pl?num=1427464747
https://mindfusion.dev/Forum/YaBB.pl?num=1447176493

If it's our pre-release build, it might had used unfinalized XML schema, and some change in final v4.1.4 breaking deserialization code (CompositeNodes were introduced in v4.1 and actively developed until v4.4).

In either case, if you attach an XML file that fails to load, our developer will trace the loadFormXml code to find exact problem (replace text values with empty strings if any secrets there).
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3518
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #5 - Sep 18th, 2026 at 12:46pm
Print Post  
I've tried the following code, save using current version -> load using current version seems to work as expected:

Code
Select All
void testCustomClassesXmlSerialization() throws Exception
{
	String tempFile = "temp_custom_classes_reproduction.xml";
	try
	{
		// Register custom classes with Diagram
		Diagram.registerItemClass(Custom1Node.class, "Custom1Node", 1);
		Diagram.registerItemClass(StyledTextComponent.class, "StyledTextComponent", 1);
		Diagram.registerItemClass(TitleNode.class, "TitleNode", 1);

		Diagram diagram1 = new Diagram();

		// TitleNode (inherits from ShapeNode)
		TitleNode titleNode = new TitleNode(diagram1);
		titleNode.setBounds(10, 10, 40, 30);
		titleNode.setText("Custom Title Node");
		diagram1.add(titleNode);

		// Custom1Node (inherits from CompositeNode)
		Custom1Node customNode = new Custom1Node(diagram1);
		customNode.setBounds(60, 10, 40, 30);

		// Add StyledTextComponent to Custom1Node
		StyledTextComponent styledTextComp = new StyledTextComponent();
		styledTextComp.setText("Custom Styled Text Component");
		customNode.getComponents().add(styledTextComp);

		diagram1.add(customNode);

		// Save to XML
		diagram1.saveToXml(tempFile);

		// Load from XML into a new Diagram instance
		Diagram diagram2 = new Diagram();
		diagram2.loadFromXml(tempFile);

		// Verification
		assert_equal(diagram1.getNodes().size(), diagram2.getNodes().size());
		assert_equal(2, diagram2.getNodes().size());

		DiagramNode loadedNode1 = diagram2.getNodes().get(0);
		DiagramNode loadedNode2 = diagram2.getNodes().get(1);

		// Assert types are correctly preserved upon loading
		assert_equal(TitleNode.class, loadedNode1.getClass());
		assert_equal(Custom1Node.class, loadedNode2.getClass());

		// Assert content is preserved
		TitleNode loadedTitle = (TitleNode)loadedNode1;
		assert_equal("Custom Title Node", loadedTitle.getText());

		Custom1Node loadedCustom = (Custom1Node)loadedNode2;
		assert_equal(1, loadedCustom.getComponents().size());
		assert_equal(StyledTextComponent.class, loadedCustom.getComponents().get(0).getClass());

		StyledTextComponent loadedComp = (StyledTextComponent)loadedCustom.getComponents().get(0);
		assert_equal("Custom Styled Text Component", loadedComp.getText());

		System.out.println("testCustomClassesXmlSerialization ok");
	}
	finally
	{
		new File(tempFile).delete();
	}
} 



but using empty classes without XML method overrides -

Code
Select All
public class Custom1Node extends CompositeNode
{
	public Custom1Node()
	{
		super();
	}

	public Custom1Node(Diagram diagram)
	{
		super(diagram);
	}

	public Custom1Node(CompositeNode prototype)
	{
		super(prototype);
	}
}

public class TitleNode extends ShapeNode
{
	public TitleNode()
	{
		super();
	}

	public TitleNode(Diagram diagram)
	{
		super(diagram);
	}

	public TitleNode(ShapeNode prototype)
	{
		super(prototype);
	}
}

public class StyledTextComponent extends TextComponent
{
	public StyledTextComponent()
	{
		super();
	}
} 



Please also post the saveToXml and loadFromXml override of your subclasses.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 73
Joined: Jan 23rd, 2015
Re: Load from XML not working with latest version of JDiagram
Reply #6 - Sep 18th, 2026 at 4:06pm
Print Post  
From experiments, each version of JDiagram we have, loads from XML fine if the data was saved to XML by the same version, but fails to load Nodes and Links if the other version of JDiagram saved to XML. (i.e. old->old and new->new are fine, but both old->new and new->old don't work)

I wouldn't necessarily expect new->old to work without some data tweaks, but it would be a problem for us if it can't be made to work.

TitleNode doesn't have SaveToXML/LoadFromXML - just has a constructor I can pass objects to which are then used to set the text of the Node.

StyledTextComponent only overrides draw( Graphics2D graphics2D, RenderOptions renderOptions ) to allow HTML text to be displayed (for coloured text mainly, where not all the text is coloured)

Custom1Node - code for LoadFromXML and SaveToXML attached.
  

LoadXMLSaveXMLCode.txt ( 0 KB | 2 Downloads )
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 73
Joined: Jan 23rd, 2015
Re: Load from XML not working with latest version of JDiagram
Reply #7 - Sep 18th, 2026 at 4:07pm
Print Post  
A sanitized example of XML which doesn't load Nodes with latest JDiagram
  

diagram-oldJDiagramJar_xml.txt ( 40 KB | 4 Downloads )
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint