Bug: Error when XML document is decoded into an existing model
I'm trying to decode XML document into a model using the following code:
1. var doc = mxUtils.parseXml(xmlString);
2. var codec = new mxCodec(doc);
3. codec.decode(doc.documentElement, graph.getModel());
and this is the xmlString:
1. <mxGraphModel>
2. <root>
3. <mxCell id="0">
4. <Object as="annotations"/>
5. </mxCell>
6. <mxCell id="1" parent="0">
7. <Object as="annotations"/>
8. </mxCell>
9. <mxCell id="2" value="bbb" style="fontSize=18;fontColor=black;strokeWidth=4" vertex="1" parent="1" type="2">
10. <mxGeometry x="620" y="200" width="130" height="80" as="geometry"/>
11. <Object name="bbb" action="bbb" as="intent">
12. <Array as="events"/>
13. <Array as="ownEventNames"/>
14. <Array as="trainingPhrases">
15. <Object name="1" type="2">
16. <Array as="parts">
17. <Object text="1" userDefined="1" alias="Param 2" entityType="@sys.number"/>
18. <Object text="" userDefined="0"/>
19. </Array>
20. </Object>
21. </Array>
22. <Array as="messages"/>
23. <Array as="parameters">
24. <Object name="Param 2" entity="sys.number" mandatory="0" isList="0">
25. <Array as="prompts"/>
26. </Object>
27. </Array>
28. <Array as="outputContexts"/>
29. <Array as="inputContexts"/>
30. <Array as="payloads"/>
31. </Object>
32. <Object as="annotations">
33. <Array>
34. <Object parameterName="Param 2" item="1" value="1">
35. <Object name="sys.number" _id="" as="entity">
36. <Array as="valuesList"/>
37. </Object>
38. </Object>
39. </Array>
40. </Object>
41. </mxCell>
42. </root>
When the command codec.decode(doc.documentElement, graph.getModel()); is executed, the following error appears:
ERROR TypeError: obj.push is not a function
at mxObjectCodec.addObjectValue (build.js:88054)
at mxObjectCodec.decodeChild (build.js:88007)
at mxObjectCodec.decodeChildren (build.js:87966)
at mxObjectCodec.decodeNode (build.js:87853)
at mxObjectCodec.decode (build.js:87832)
at mxCodec.decode (build.js:86875)
at mxObjectCodec.decodeChild (build.js:88004)
at mxObjectCodec.decodeChildren (build.js:87966)
at mxObjectCodec.decodeNode (build.js:87853)
at mxObjectCodec.decode (build.js:87832)
I realized that when the text value (line 17 at xmlString) is a letter, everything works fine.
I'm using mxGraph 3.9.1 at Angular 5.
Has anyone seen this error and knows how to fix it?
The object annotations is incorrect
<Object as="annotations">
<Array>
<Object parameterName="Param 2" item="1" value="1">
<Object name="sys.number" _id="" as="entity">
<Array as="valuesList" />
</Object>
</Object>
</Array>
</Object>
Whether to name the child Array. E.g, <Object as="annotations">
<Array as="annotationsArray">
<Object parameterName="Param 2" item="1" value="1">
<Object name="sys.number" _id="" as="entity">
<Array as="valuesList" />
</Object>
</Object>
</Array>
</Object>
or change annotations type to be an array. E.g, <Array as="annotations">
<Object parameterName="Param 2" item="1" value="1">
<Object name="sys.number" _id="" as="entity">
<Array as="valuesList" />
</Object>
</Object>
</Array>
We have a question, how the original XML is generated?