从gojs转换json模型到xml

时间:2015-04-18 14:40:58

标签: javascript xml json gojs

我使用gojs创建一个类图并获取json模型数据,我知道你可以从xml读取它,有没有办法用XML DOM将它写入xml?谢谢

jQuery.ajax({       url:" class.xml",       成功:加载,       dataType:" xml"     });

function load(x){     var xml = jQuery(x.xml?x.xml:x);     classd.model = new go.GraphLinksModel(xml.find(" node")。toArray(),xml.find(" link")。toArray());

}

1 个答案:

答案 0 :(得分:0)

GoJS默认只支持读写JSON模型。如果要读写XML,则需要使用常规JavaScript对象,并从XML实现自己的持久性。

这里有一个非常简单的从XML加载的例子:http://gojs.net/latest/samples/minimalXML.html

它确实:

    // The previous initialization is the same as the minimal.html sample.
    // Here we request XML-format text data from the server, in this case from a static file.
    jQuery.ajax({
      url: "minimal.xml",
      success: load,
      dataType: "xml"
    });
  }

  function load(x) {
    // ought to handle parse errors here:
    var xml = jQuery(x.xml ? x.xml : x);
    // this does direct binding to XML DOM elements:
    myDiagram.model = new go.GraphLinksModel(xml.find("node").toArray(), xml.find("link").toArray());
    // such binding is read-only at the current time
  }