Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic An error while loading from xml (Read 4814 times)
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
An error while loading from xml
Oct 7th, 2016 at 1:20pm
Print Post  
Hello,

I am getting an error when trying to load from xml

Code (Javascript)
Select All
    var xmlUrl = "http://localhost:1234/template.xml";

    diagram.loadFromXml(xmlUrl, OnSuccesfulXmlLoad, OnErrorLoadingXml);

 



An error:
Code (Javascript)
Select All
return p.attributes.getNamedItem("Id").value||"RoundRect"}
 



and p.attributes.getNamedItem("Id") is null

Well i using custom shape node and custom diagraming link they are described in template.xml like 'ns:MyCustomNode' and 'ns:MyCustomDiagramingLink'

well they are plain empty. What i have declared is:

Code (Javascript)
Select All
var MyCustomShapeNode = function (parent)
{
	AbstractionLayer.initializeBase(MyCustomShapeNode, this, [parent]);
}


MyCustomShapeNode.prototype =
{
     // i have these line removed, since samples not using similar init/disp.
    //initialize: function () {
    //    AbstractionLayer.callBaseMethod(this, 'initialize');
    //},

    //dispose: function () {
    //    AbstractionLayer.callBaseMethod(this, 'dispose');
    //},
}

 




What could be wrong?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: An error while loading from xml
Reply #1 - Oct 7th, 2016 at 1:29pm
Print Post  
Is template.xml a file created by Diagram.saveToXml and could you attach it here?
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: An error while loading from xml
Reply #2 - Oct 7th, 2016 at 2:08pm
Print Post  
Slavcho wrote on Oct 7th, 2016 at 1:29pm:
Is template.xml a file created by Diagram.saveToXml and could you attach it here?


Sure, but the problem is not in xml file, because i load the same in webforms it works just fine. It is more like i can't figure out something.

p.s. i've attached file, just rename to *.xml
  

template.txt ( 16 KB | 134 Downloads )
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: An error while loading from xml
Reply #3 - Oct 7th, 2016 at 2:24pm
Print Post  
more on this line:
return p.attributes.getNamedItem("Id").value||"RoundRect"}

where p is "LinkHeadShape"
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: An error while loading from xml
Reply #4 - Oct 7th, 2016 at 2:32pm
Print Post  
If i add Id attribute to <LinkHeadShape> tag, then i get error: Item classId ["ns:CustomNode"] is not registered.

which happens here:
Code (Javascript)
Select All
instantiateItem:function(s,p){var q=this.diagram.xmlClassMap[s];if(!q){throw new Error("Item classId ["+s+"] is not registered.")}
 



i have registered them like so:

Code (Javascript)
Select All
$(document).ready(function () {

    AbstractionLayer.registerClass(CustomNode, "ns:CustomNode", MindFusion.Diagramming.ShapeNode);
    AbstractionLayer.registerClass(CustomLink, "ns:CustomLink", MindFusion.Diagramming.DiagramLink);

....
 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: An error while loading from xml
Reply #5 - Oct 10th, 2016 at 6:28am
Print Post  
This xml file is in some ancient XML format of ours, have you used older ActiveX or Windows Forms version to save it? We've added XML serialization in JavaScript library only recently and current official build works with latest format #17 of XML files, yours is <Diagram Version="12">. It happens we've just implemented some backwards compatibility for a client, it seems it can also load your template.xml file as well -
https://mindfusion.eu/_beta/jsdiag271.zip

The build above officially supports versions as old as 13 though, we'll check what differences there are from 12 to it.

Quote:
because i load the same in webforms it works just fine


WebForms version already has backwards compatibilty in its .NET LoadFromXml implementation, then it sends contents to client side as JSON.

Quote:
If i add Id attribute to <LinkHeadShape> tag, then i get error: Item classId ["ns:CustomNode"] is not registered


The second parameter of that registerClass method is not XML id but fully qualified type name (with added namespace). It doesn't seem we offer public API to register XML identifiers for custom classes directly in JavaScript. For time being you could implement that by replacing following function in Diagram.prototype with your version that adds new identifiers -

Code
Select All
var Dictionary = MindFusion.Collections.Dictionary;
registerXmlTypes: function ()
{
	var xmlClassMap = new Dictionary();

	function register(ctor, classId, classVersion)
	{
		xmlClassMap[classId] = ctor;
		ctor.xmlInfo = { classId: classId, classVersion: classVersion };
	}

	register(mdiag.DiagramLink, "std:DiagramLink", 2);
	register(mdiag.ShapeNode, "std:ShapeNode", 1);
	register(mdiag.TableNode, "std:TableNode", 1);
	register(mdiag.ContainerNode, "std:ContainerNode", 3);
	register(mdiag.SvgNode, "std:SvgNode", 2);
	register(mdiag.FreeFormNode, "std:FreeFormNode", 1);

	register(mdiag.GlassEffect, "std:GlassEffect", 1);
	register(mdiag.AeroEffect, "std:AeroEffect", 1);

	return xmlClassMap;
} 



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


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: An error while loading from xml
Reply #6 - Oct 10th, 2016 at 9:54am
Print Post  
Thanks, that is very helpful.  Can you elaborate a bit more one diagram prototype declaration?

This is how i am currently declaring:

Code (Javascript)
Select All
 Diagram.prototype = {

    registerXmlTypes: function () {

        var xmlClassMap = new Dictionary();

        function register(ctor, classId, classVersion) {
            xmlClassMap[classId] = ctor;
            ctor.xmlInfo = { classId: classId, classVersion: classVersion };
        }

        register(mdiag.ShapeNode, "ns:CustomNode", 1);
        register(mdiag.DiagramLink, "ns:CustomLink", 1);

        return xmlClassMap;
    }
};
  ...
  AbstractionLayer.registerClass(Diagram, "Diagram", MindFusion.Diagramming.Diagram);
  AbstractionLayer.registerClass(CustomNode, "CustomNode", MindFusion.Diagramming.ShapeNode);
  AbstractionLayer.registerClass(CustomLink, "CustomLink", MindFusion.Diagramming.DiagramLink);

  diagram = AbstractionLayer.createControl(Diagram, null, null, null, $("#diagram")[0]);

 



After this code line registered <...>registerClass(Diagram, <..> i am getting an error "Out of stack space"
To what it could be related?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: An error while loading from xml
Reply #7 - Oct 10th, 2016 at 10:26am
Print Post  
Set it like his -

Diagram.prototype.registerXmlTypes = function() ...

and do not remove the standard class registrations but only add your two lines after them.

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


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: An error while loading from xml
Reply #8 - Oct 10th, 2016 at 10:50am
Print Post  
Slavcho wrote on Oct 10th, 2016 at 10:26am:
Set it like his -

Diagram.prototype.registerXmlTypes = function() ...

and do not remove the standard class registrations but only add your two lines after them.

Regards,
Slavcho
Mindfusion



Hm, that did not helped : / same result. Chrome says Uncaught RangeError: Maximum call stack size exceeded
and IE says Out of stack space, i guess the same error, can't really see where it is happening. I think it is even before calling registerXmlTypes methods, i added to registerXmlTypes console.log lines...

Another question, new version of jsDiagramming will be with backwards XML comparability ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: An error while loading from xml
Reply #9 - Oct 10th, 2016 at 12:22pm
Print Post  
Attached modified sample seems to load the file successfully, using 2.7.1 build from above.
  

Samples.zip ( 242 KB | 183 Downloads )
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint