0
XML 파일에서 그래프를 작성하려고하지만 특정 조건을 기반으로하는 노드 만로드하려고합니다 ... 추가 할 모든 정점을 얻을 수 있습니다. 디코드를 포함하고 기능을 추가 루프에 대한소스 또는 대상을 잃지 않고 xml에서 가장자리를 동적으로 추가하는 방법
문제는 내가 그들을 항상 원하지만 목표를 가지고 내가 최종 버전 시도하는 많은 것들 사이에 널 (null)
을 바람 얻을 수 있습니다 .. 가장자리되는 XML을 추가 노드를 배열에 추가하고 모든 정점을 그래프에 추가 한 후에는 가장자리를 디코딩합니까?하지만 여전히 작동하지 않습니다 ...
function get_selected(main_class, filename){
"use strict";
var node, i, j, req, root, decj, deci, enc, dec, data, parent, graph, main_class_node, child_nodes, edges, destinations;
deci = new mxCodec();
decj = new mxCodec();
graph = new mxGraph();
parent = graph.getDefaultParent();
req = mxUtils.load(filename);
root = req.getDocumentElement();
child_nodes = [];
edges = [];
destinations = [];
mxLog.show();
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
// Get the main cell and add it to the graph
if (root.childNodes[0].childNodes[i].id == main_class) {
node = deci.decode(root.childNodes[0].childNodes[i]);
main_class_node = graph.getModel().add(parent, node);
}
//get all the children of the main cell and add them to the graph
else if (root.childNodes[0].childNodes[i].outerHTML.indexOf('parent="' + main_class + '"') != -1) {
node = decj.decode(root.childNodes[0].childNodes[i]);
graph.getModel().add(main_class_node, node);
child_nodes.push(node.id);
}
}
for (j=0; j < child_nodes.length; j ++) {
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
//get all the edges originating in any of the "chidren" and add them to the graph
if (root.childNodes[0].childNodes[i].outerHTML.indexOf('source="' + child_nodes[j] + '"') != -1) {
node = root.childNodes[0].childNodes[i];
//graph.getModel().add(parent, node);
edges.push(node);
}
}
}
for (j=0; j < edges.length; j ++) {
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
//get the target of each of the edges and and add them to the graph
if (root.childNodes[0].childNodes[i].id == "attr-" + edges[j].id.split('-')[1]) {
node = deci.decode(root.childNodes[0].childNodes[i]);
graph.getModel().add(parent, node);
}
}
}
dec = new mxCodec();
for (j=0; j < edges.length; j ++) {
node = dec.decode(edges[j]);
graph.getModel().add(parent, node);
}
enc = new mxCodec();
data = enc.encode(graph.getModel());
return mxUtils.getXml(data);
}