[英]Read/Parse Custom Xml in the mxgraph
我有从第三方应用程序创建的自定义 xml,它是关于电子数据的数据(图表)。现在我想在 mxgraph 中重写相同的数据。
请找到第三方应用的示例xml
<component type="Rerror" mirrored="0" typeid="57" nodematch="0" macrotype="2" position="280,260" orientation="0">
<parameter idx="0" encrypted="0">
data unrelated to drawing here
</parameter>
<image>
<hotzone points="60,-10,-60,10"/>
<shape type="line" width="1" color="#0000ff" points="60,0,40,0"/>
<shape type="line" width="1" color="#0000ff" points="40,0,30,-10"/>
<shape type="line" width="1" color="#0000ff" points="30,-10,10,10"/>
<shape type="line" width="1" color="#0000ff" points="10,10,-10,-10"/>
<shape type="line" width="1" color="#0000ff" points="-10,-10,-30,10"/>
<shape type="line" width="1" color="#0000ff" points="-30,10,-40,0"/>
<shape type="line" width="1" color="#0000ff" points="-40,0,-60,0"/>
<legend text="0.332 MOhm" position="-36,20" orientation="0" fontname="Arial" fontsize="12" bold="0" italic="0" color="#229922"/>
<pin position="-60,0" dir="0" length="0" text="6"/>
<pin position="60,0" dir="0" length="0" text="3"/>
<label text="Rerror" position="250,236" textroot=" " orientation="0" color="#228822"/>
</image>
</component>
上面的 xml 必须使用 mxgraph 解析和重绘。 在哪里
component : 是特定单元的整体图像(可以有很多组件
参数:这部分应该被忽略
图像:图像部分包含必须在图形中绘制的 x,y 坐标的数据
我正在阅读 mxgraph 用户指南 & 我是 mxgraph 的新手。我能够使用“mxUtils.parseXml('location')”看到 xml 的正常prase请帮助我如何解析自定义文件
mxGraph 不支持开箱即用的自定义 xml 支持。 实际上没有这样的工具可以将自定义转换为 mxGraph 可读的 xml。 最近我们尝试使用 xsds 将我们的自定义 xml 转换为图形。 使用 xsd 方法是处理 xmls 的更好方法。 尝试以下步骤
就如此容易。
parseXML()
只会使它更容易在代码中使用(如果需要,可以创建一个 DOM 文档),但您必须手动编写“转换器”。
对于文件的每个<shape>
,创建一个 mxCell。 为您的各种单元格创建不同的样式,您就完成了。
如果您的所有形状都是矩形,那应该相当简单!
将您的 xml 转换为 java 对象。 这与 JGraph 无关。 如果 .xsd 可用,您可以使用 JAXB 例如。
从 xml 中获得 java 对象后,就可以使用其中包含的信息来创建边和顶点。 在基于 JGraph 的应用程序中, mxGraph
类具有方法insertVertex
和insertEdge
,它们将您的位置和标签作为参数。 例如,您可以遍历从 XML 解析的 java 对象,并为每个对象调用graph.insertVertex()
。
如果mxGraph
对象不是直接可用的,您可以使用mxGraphComponent.getGraph()
来访问它。 mxGraphComponent
应该可以从您选择的编辑器中获取,即。 editor.getGraphComponent()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.