Javascript 在mxgraph中读取/解析自定义Xml

Javascript 在mxgraph中读取/解析自定义Xml,javascript,xml,mxgraph,Javascript,Xml,Mxgraph,我有从第三方应用程序创建的自定义xml,它是关于电子数据的数据(图表)。现在我想在mxgraph中重写相同的数据请查找第三方应用程序的示例xml <component type="Rerror" mirrored="0" typeid="57" nodematch="0" macrotype="2" position="280,260" orientation=&

我有从第三方应用程序创建的自定义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>

与此处绘图无关的数据
必须使用mxgraph解析和重绘上述xml。 在哪里

  • 组件:是粒子单元的整体图像(可以有许多组件

  • 参数:此部分应为igonred

  • 图像:图像部分包含必须在图形中绘制的x,y坐标的数据


我正在阅读mxgraph用户指南&我是mxgraph新手。我能够使用“mxUtils.parseXml('location')”看到xml的正常用法 请帮助我如何解析自定义文件

parseXML()
只会使其更易于在代码中使用(如果需要,可以创建DOM文档),但您必须手动编写“转换器”

对于文件的每个
,创建一个mxCell。为不同的单元格创建不同的样式,就完成了


如果您的所有形状都是矩形,那么应该非常简单!

mxGraph不支持现成的自定义xml支持。事实上,没有这样的工具可以将自定义xml转换为mxGraph可读的xml。最近,我们尝试使用xsd将自定义xml转换为图形。使用xsd方法是处理xml的更好方法。请尝试下列步骤

  • 如果您的自定义xml有xsd,那么就用它创建java类(您的xml看起来更简单,如果您没有xsd,就可以创建它)
  • 从internet获取mxGraph xsd。(虽然他们官方没有发布任何xsd,但internet上有可用的版本)
  • 从自定义xml java类读取数据,并将其填充到mxGraph xml java类中
就这么简单

  • 将xml转换为java对象。这与JGraph无关。如果.xsd可用,可以使用JAXB作为示例

  • 从xml中获取java对象后,可以使用其中包含的信息创建边和顶点。在基于JGraph的应用程序中,
    mxGraph
    类具有方法
    insertVertex
    insertEdge
    ,这些方法将您的位置和标签作为参数。例如,您可以通过ht从XML解析的java对象,并为每个对象调用
    graph.insertVertex()

  • 如果
    mxGraph
    对象不直接可用,您可以使用
    mxGraphComponent.getGraph()
    访问它。
    mxGraphComponent
    应该可以从您选择的编辑器中获得,即
    editor.getGraphComponent()


  • 谢谢,我也在尝试同样的东西。嗨,巴拉,你能告诉我我一直在学习mxGraph xml类。我现在正在阅读我的java自定义xml。你到底在哪里被打动了?如何将当前对象转换为mxGraph对象。我不知道如何才能做到。任何转换的例子都会对我有很大帮助,因为我对mxGraph完全陌生东西