GraphML的扩展是基于xml的扩展方式,通过增加namespace的引用就可以容易地扩展GraphML,包括xml属性的扩展和Complex Type的扩展。
属性扩展
xsd定义:
graphml+xlink.xsd
<?
xml version="1.0" encoding="UTF-8"
?>
< xs:schema
targetNamespace ="http://graphml.graphdrawing.org/xmlns"
xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:xlink ="http://www.w3.org/1999/xlink"
xmlns:xs ="http://www.w3.org/2001/XMLSchema"
elementFormDefault ="qualified"
attributeFormDefault ="unqualified"
>
< xs:import namespace ="http://www.w3.org/1999/xlink"
schemaLocation ="xlink.xsd" />
< xs:redefine
schemaLocation ="http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" >
< xs:attributeGroup name ="node.extra.attrib" >
< xs:attributeGroup ref ="node.extra.attrib" />
< xs:attribute ref ="xlink:href" use ="optional" />
</ xs:attributeGroup >
</ xs:redefine >
</ xs:schema >
< xs:schema
targetNamespace ="http://graphml.graphdrawing.org/xmlns"
xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:xlink ="http://www.w3.org/1999/xlink"
xmlns:xs ="http://www.w3.org/2001/XMLSchema"
elementFormDefault ="qualified"
attributeFormDefault ="unqualified"
>
< xs:import namespace ="http://www.w3.org/1999/xlink"
schemaLocation ="xlink.xsd" />
< xs:redefine
schemaLocation ="http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" >
< xs:attributeGroup name ="node.extra.attrib" >
< xs:attributeGroup ref ="node.extra.attrib" />
< xs:attribute ref ="xlink:href" use ="optional" />
</ xs:attributeGroup >
</ xs:redefine >
</ xs:schema >
例子
<?
xml version="1.0" encoding="UTF-8"
?>
< graphml xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:xlink ="http://www.w3.org/1999/xlink"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://graphml.graphdrawing.org/xmlns
graphml+xlink.xsd" >
< graph edgedefault ="directed" >
< node id ="n0" xlink:href ="http://graphml.graphdrawing.org" />
< node id ="n1" />
< edge source ="n0" target ="n1" />
</ graph >
</ graphml >
< graphml xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:xlink ="http://www.w3.org/1999/xlink"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://graphml.graphdrawing.org/xmlns
graphml+xlink.xsd" >
< graph edgedefault ="directed" >
< node id ="n0" xlink:href ="http://graphml.graphdrawing.org" />
< node id ="n1" />
< edge source ="n0" target ="n1" />
</ graph >
</ graphml >
Complex Type扩展
xsd定义:
graphml+svg.xsd
<?
xml version="1.0" encoding="UTF-8"
?>
< xs:schema
targetNamespace ="http://graphml.graphdrawing.org/xmlns"
xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:svg ="http://www.w3.org/2000/svg"
xmlns:xs ="http://www.w3.org/2001/XMLSchema"
elementFormDefault ="qualified"
attributeFormDefault ="unqualified"
>
< xs:import namespace ="http://www.w3.org/2000/svg"
schemaLocation ="svg.xsd" />
< xs:redefine
schemaLocation ="http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" >
< xs:complexType name ="data-extension.type" >
< xs:complexContent >
< xs:extension base ="data-extension.type" >
< xs:sequence >
< xs:element ref ="svg:svg" />
</ xs:sequence >
</ xs:extension >
</ xs:complexContent >
</ xs:complexType >
</ xs:redefine >
</ xs:schema >
< xs:schema
targetNamespace ="http://graphml.graphdrawing.org/xmlns"
xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:svg ="http://www.w3.org/2000/svg"
xmlns:xs ="http://www.w3.org/2001/XMLSchema"
elementFormDefault ="qualified"
attributeFormDefault ="unqualified"
>
< xs:import namespace ="http://www.w3.org/2000/svg"
schemaLocation ="svg.xsd" />
< xs:redefine
schemaLocation ="http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" >
< xs:complexType name ="data-extension.type" >
< xs:complexContent >
< xs:extension base ="data-extension.type" >
< xs:sequence >
< xs:element ref ="svg:svg" />
</ xs:sequence >
</ xs:extension >
</ xs:complexContent >
</ xs:complexType >
</ xs:redefine >
</ xs:schema >
例子:
<?
xml version="1.0" encoding="UTF-8"
?>
< graphml xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:svg ="http://www.w3.org/2000/svg"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://graphml.graphdrawing.org/xmlns
graphml+svg.xsd" >
< key id ="k0" for ="node" >
< default >
< svg:svg width ="5cm" height ="4cm" version ="1.1" >
< svg:desc > Default graphical representation for nodes
</ svg:desc >
< svg:rect x ="0.5cm" y ="0.5cm" width ="2cm" height ="1cm" />
</ svg:svg >
</ default >
</ key >
< key id ="k1" for ="edge" >
< desc > Graphical representation for edges
</ desc >
</ key >
< graph edgedefault ="directed" >
< node id ="n0" >
< data key ="k0" >
< svg:svg width ="4cm" height ="8cm" version ="1.1" >
< svg:ellipse cx ="2cm" cy ="4cm" rx ="2cm" ry ="1cm" />
</ svg:svg >
</ data >
</ node >
< node id ="n1" />
< edge source ="n0" target ="n1" >
< data key ="k1" >
< svg:svg width ="12cm" height ="4cm" viewBox ="0 0 1200 400" >
< svg:line x1 ="100" y1 ="300" x2 ="300" y2 ="100"
stroke-width ="5" />
</ svg:svg >
</ data >
</ edge >
</ graph >
</ graphml >
< graphml xmlns ="http://graphml.graphdrawing.org/xmlns"
xmlns:svg ="http://www.w3.org/2000/svg"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://graphml.graphdrawing.org/xmlns
graphml+svg.xsd" >
< key id ="k0" for ="node" >
< default >
< svg:svg width ="5cm" height ="4cm" version ="1.1" >
< svg:desc > Default graphical representation for nodes
</ svg:desc >
< svg:rect x ="0.5cm" y ="0.5cm" width ="2cm" height ="1cm" />
</ svg:svg >
</ default >
</ key >
< key id ="k1" for ="edge" >
< desc > Graphical representation for edges
</ desc >
</ key >
< graph edgedefault ="directed" >
< node id ="n0" >
< data key ="k0" >
< svg:svg width ="4cm" height ="8cm" version ="1.1" >
< svg:ellipse cx ="2cm" cy ="4cm" rx ="2cm" ry ="1cm" />
</ svg:svg >
</ data >
</ node >
< node id ="n1" />
< edge source ="n0" target ="n1" >
< data key ="k1" >
< svg:svg width ="12cm" height ="4cm" viewBox ="0 0 1200 400" >
< svg:line x1 ="100" y1 ="300" x2 ="300" y2 ="100"
stroke-width ="5" />
</ svg:svg >
</ data >
</ edge >
</ graph >
</ graphml >