【问题标题】:Adjust XML output in GraphML在 GraphML 中调整 XML 输出
【发布时间】:2025-11-22 09:05:02
【问题描述】:

你认为我可以调整 GraphML 的 xml 输出吗?

GraphML wiki 中的标签似乎是固定的:

<graphml>
  <graph>
    <node>
      <data></data>
    </node>
    <edge>
      <data></data>
    </edge>
  </graph>
</graphml>

我看到您可以更改标签属性。 你认为我可以将标签本身自定义为&lt;car&gt;&lt;/car&gt; 之类的东西吗?

【问题讨论】:

    标签: markup xml-namespaces custom-tag graphml


    【解决方案1】:

    如果您需要添加新元素,则必须修改the DTD。在这种情况下,由于DTD customization,您的数据将不再是 GraphML,而是您自己的标准。这是 GraphML DTD:

    <!-- ====================================================================== -->
    <!-- file: graphml.dtd ====================================================== 
    
      This is the Document Type Definition for the release candidate of 
      GraphML version 1.0 and represents a (necessarily) looser specification 
      than the corresponding XML Schema.  It's use is discouraged, though it
      may be necessary for some systems.
    
      Usage:
    
                SYSTEM "http://graphml.graphdrawing.org/dtds/1.0rc/graphml.dtd"
    
                xmlns="http://graphml.graphdrawing.org/xmlns/1.0rc"
    
        ====================================================================== -->
    
    <!-- ===============================================================-->
    <!--Parameter entity for data content -->
    <!--================================================================-->
    
    <!ENTITY % GRAPHML.data.content "(#PCDATA)">
    
    <!-- ===============================================================-->
    <!--Parameter entities for attribute list extensions -->
    <!--================================================================-->
    
    <!ENTITY % GRAPHML.graphml.attrib "">
    <!ENTITY % GRAPHML.locator.attrib "">
    <!ENTITY % GRAPHML.graph.attrib "">
    <!ENTITY % GRAPHML.node.attrib "">
    <!ENTITY % GRAPHML.port.attrib "">
    <!ENTITY % GRAPHML.edge.attrib "">
    <!ENTITY % GRAPHML.hyperedge.attrib "">
    <!ENTITY % GRAPHML.endpoint.attrib "">
    <!ENTITY % GRAPHML.key.attrib "">
    <!ENTITY % GRAPHML.data.attrib "">
    <!ENTITY % GRAPHML.default.attrib "">
    
    <!--============================================================-->
    <!--Attributes used by each GRAPHML element-->
    <!--============================================================-->
    
    <!ENTITY % GRAPHML.common.attrib
               ""
    >
    
    <!--================================================================-->
    <!--the graphml elements-->
    <!--================================================================-->
    
    <!ELEMENT data  %GRAPHML.data.content;>
    <!ATTLIST data 
                    key            IDREF   #REQUIRED
                    id             ID      #IMPLIED
                    %GRAPHML.data.attrib;
                    %GRAPHML.common.attrib;
    >
    
    <!ELEMENT default  %GRAPHML.data.content;>
    <!ATTLIST default 
                    %GRAPHML.default.attrib;
                    %GRAPHML.common.attrib;
    >
    
    <!ELEMENT key (desc?,default?)>
    <!ATTLIST key 
                  id  ID       #REQUIRED
                  for (graph|node|edge|hyperedge|port|endpoint|all) "all"
                  %GRAPHML.key.attrib;
                  %GRAPHML.common.attrib;
    >   
    
    <!ELEMENT graphml  (desc?,key*,(data|graph)*)>
    <!ATTLIST graphml  
                       %GRAPHML.graphml.attrib;
                       %GRAPHML.common.attrib;
    >
    
    <!ELEMENT graph    (desc?,(((data|node|edge|hyperedge)*)|locator))>
    <!ATTLIST graph    
                       id       ID           #IMPLIED
                       edgedefault (directed|undirected) #REQUIRED
                       %GRAPHML.graph.attrib;
                       %GRAPHML.common.attrib;
    >   
    
    <!ELEMENT node   (desc?,((((data|port)*,graph?))|locator))>
    <!ATTLIST node   
                     id        ID      #REQUIRED
                     %GRAPHML.node.attrib;
                     %GRAPHML.common.attrib;
    >
    
    <!ELEMENT port (desc?,(data|port)*)>
    <!ATTLIST port
                   name    NMTOKEN  #REQUIRED
                   %GRAPHML.port.attrib;
                   %GRAPHML.common.attrib;
    >
    
    
    <!ELEMENT edge (desc?,data*,graph?)>
    <!ATTLIST edge 
                   id         ID           #IMPLIED
                   source     IDREF        #REQUIRED
                   sourceport NMTOKEN      #IMPLIED
                   target     IDREF        #REQUIRED
                   targetport NMTOKEN      #IMPLIED
                   directed   (true|false) #IMPLIED
                   %GRAPHML.edge.attrib;
                   %GRAPHML.common.attrib;
    >
    
    <!ELEMENT hyperedge  (desc?,(data|endpoint)*,graph?)>
    <!ATTLIST hyperedge 
                        id     ID      #IMPLIED
                        %GRAPHML.hyperedge.attrib;
                        %GRAPHML.common.attrib;
    >
    
    <!ELEMENT endpoint (desc?)>
    <!ATTLIST endpoint 
                       id    ID       #IMPLIED
                       node  IDREF    #REQUIRED
                       port  NMTOKEN  #IMPLIED
                       type  (in|out|undir) "undir"
                       %GRAPHML.endpoint.attrib;
                       %GRAPHML.common.attrib;
    >
    
    <!ELEMENT locator EMPTY>
    <!ATTLIST locator 
                       xmlns:xlink   CDATA   #FIXED  "http://www.w3.org/TR/2000/PR-xlink-20001220/"
                       xlink:href     CDATA    #REQUIRED
                       xlink:type     (simple) #FIXED    "simple"
                       %GRAPHML.locator.attrib;
                       %GRAPHML.common.attrib; 
    >
    
    <!ELEMENT desc (#PCDATA)>
    <!ATTLIST desc %GRAPHML.common.attrib;>
    

    参考文献

    【讨论】:

      最近更新 更多