首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载xml-file并仅显示顶点

加载xml-file并仅显示顶点
EN

Stack Overflow用户
提问于 2019-09-25 16:49:35
回答 2查看 158关注 0票数 0

如何在我的mxGraphModel中加载以下draw.io文件并只显示顶点而不显示边?

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="www.draw.io" modified="2019-09-25T08:10:42.119Z" agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0" etag="rVOYKV4DccHE-o70O52h" version="11.3.1" pages="1">
  <diagram id="VCf34-Iv6E_k61pAP0pe" name="Page-1">
    <mxGraphModel dx="1248" dy="594" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
      <root>
        <mxCell id="0"/>
        <mxCell id="1" parent="0"/>
        <mxCell id="VXw29pc5vOmcNuhHpu7d-5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="VXw29pc5vOmcNuhHpu7d-2" target="VXw29pc5vOmcNuhHpu7d-4">
          <mxGeometry relative="1" as="geometry"/>
        </mxCell>
        <mxCell id="VXw29pc5vOmcNuhHpu7d-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="VXw29pc5vOmcNuhHpu7d-2" target="VXw29pc5vOmcNuhHpu7d-6">
          <mxGeometry relative="1" as="geometry"/>
        </mxCell>

        [... some more vertices and edges ...]

      </root>
    </mxGraphModel>
  </diagram>
</mxfile>

提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2019-10-07 17:56:12

好的,因为您已经加载了包含xml的doc对象,所以您可以使用以下代码仅解析和绘制顶点:

代码语言:javascript
复制
let xml = '<root>...</root>'; //your xml
let doc = mxUtils.parseXml(xml);
let codec = new mxCodec(doc);
codec.decode(doc.documentElement, graph.getModel());
let elt = doc.documentElement.firstChild;
let cells = [];
while (elt != null)
{ 
    let cell = codec.decode(elt);
    if(cell != undefined){
        if(cell.vertex){
          cells.push(cell);
        }
    }

    elt = elt.nextSibling;
}

//add the vertices in the graph
graph.addCells(cells);
票数 1
EN

Stack Overflow用户

发布于 2019-10-08 16:36:13

在您的示例中,您将处理一个字符串。我没有字符串,而是一个xml文件。如何加载xml文件并准备好使用给定的函数处理它?

如果必须是字符串:如何加载xml文件并将其转换为字符串?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58094616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档