Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Load from XML not working with latest version of JDiagram (Read 680 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 77
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 | 28 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3529
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: 3529
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: 77
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 | 21 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3529
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: 3529
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: 77
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 | 21 Downloads )
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 77
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 | 40 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3529
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #8 - Sep 21st, 2026 at 9:45am
Print Post  
Quote:
No error is thrown but 'diagram.getNodes()' returns empty array.


We did get following exception thrown when loading the diagram-oldJDiagramJar_xml file, are you sure it's not happening in your catch -> log block too?

Code
Select All
com.mindfusion.common.XmlException: java.lang.IllegalArgumentException: Illegal base64 character a
	at com.mindfusion.diagramming.Diagram.loadFromXml(Diagram.java:2698)
	at com.mindfusion.diagramming.Diagram.loadFromXml(Diagram.java:2546)
	at test.diagramming.ReproductionTests.testLoadXmlDocV413(ReproductionTests.java:179)
	at test.diagramming.ReproductionTests.allTests(ReproductionTests.java:35)
	at test.diagramming.ReproductionTests.main(ReproductionTests.java:21)
Caused by: java.lang.IllegalArgumentException: Illegal base64 character a
	at java.util.Base64$Decoder.decode0(Unknown Source)
	at java.util.Base64$Decoder.decode(Unknown Source)
	at java.util.Base64$Decoder.decode(Unknown Source)
	at com.mindfusion.diagramming.Converter.toImage(Converter.java:219)
	at com.mindfusion.diagramming.XmlPersistContext.readImageContent(XmlPersistContext.java:2450)
	at com.mindfusion.diagramming.XmlPersistContext.readImages(XmlPersistContext.java:2442)
	at com.mindfusion.diagramming.Diagram.loadFromXml(Diagram.java:2593)
	... 4 more 



so that's thrown because of the newline symbols in base64 values (encoded bitmap images).

Looking at our commit history, 2014 is the year Java 8 was released, adding java.util.Base64 decoder to the standard library. So for 4.1.4 version of JDiagram, we replaced a custom decoder we were using with Java's Base64.getDecoder() result, which apparently does not allow white spaces and new-lines symbols.

Now we've replaced that again with Base64.getMimeDecoder() instead, which does allow new-lines, and the files loaded successfully in our test. Please try this build to see if it works for you too -

https://mindfusion.dev/_temp/jdiag491_base64_patch.zip

If it's still not working, another thing we could investigate is the "Id" value saved by the custom node for roleId, as this might interfere with DiagramItem's built-in Id serialization (though that's for storing custom values anyway so it shouldn't be that dangerous).

Regards,
Slavcho
Mindfusion
« Last Edit: Sep 21st, 2026 at 12:16pm by Slavcho »  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 77
Joined: Jan 23rd, 2015
Re: Load from XML not working with latest version of JDiagram
Reply #9 - Sep 21st, 2026 at 3:20pm
Print Post  
That worked - everything, including non-sanitized data, loaded without any error at all.

Thank you for all the work you've put into helping me with this.

Diagrams saved to XML with this new Jar file get an 'unsupported file format' exception if I try to load them with our original (very old) Jar file - is this expected?

I assume there is nothing that can be done about this?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3529
Joined: Oct 19th, 2005
Re: Load from XML not working with latest version of JDiagram
Reply #10 - Sep 22nd, 2026 at 9:30am
Print Post  
Comparing schema 16 vs 18 versions of your file, the only major difference I'm seeing is in the format of the Constraints property of DiagramNode.

If your application does not apply node constraints, you could try just changing the Version attribute of root <Diagram> element from 18 to 16 after saving to a Document with new jar, and before passing to the database (assuming the save code is symmetric to the load one from txt atatchment above, that goes through DocumentBuilder -> Document). You shouldn't get "unsupported file format" exception then when loading with old jar, and I imagine loaded nodes should just keep a default NodeConstraints instance, but that needs some testing.

There could be more changes to work around if your application also uses ContainerNodes.

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


I Love MindFusion!

Posts: 77
Joined: Jan 23rd, 2015
Re: Load from XML not working with latest version of JDiagram
Reply #11 - Sep 23rd, 2026 at 11:32am
Print Post  
We don't use Node Constraints - changing the Diagram Version within the XML before saving it to the database successfully allowed opening the diagram in older versions of our product which use the older JDiagram jar file.

Thank you very much for this workaround.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint