开发者

How to query graphml using php, DomDocument and DomXPath?

Does someone know how to query a graphml document with php, DomDocument and DomXpath? My query seems to be correct. e.g. //graphml/graph/node

$dom = new DomDocument();
$dom->load("doc.graphml");

$x = new DOMXPath($dom);
$x->registerNamespace('y', "http://www.yworks.com/xml/graphml");
$r = $x->query("//graphml/graph/node");

echo $r->length;

The returned length is always 0; But it has to be 1.

XML:

<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:y="http://www.yworks.com/xml/graphml"
         xmlns:yed="http://www.yworks.com/xml/yed/3"
         xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
  <!--Created by yFiles for Java 2.8-->
  <key for="graphml" id="d0" yfiles.type="resources"/>
  <key for="port" id="d1" yfiles.type="portgraphics"/>
  <key for="p开发者_StackOverflow社区ort" id="d2" yfiles.type="portgeometry"/>
  <key for="port" id="d3" yfiles.type="portuserdata"/>
  <key attr.name="url" attr.type="string" for="node" id="d4"/>
  <key attr.name="description" attr.type="string" for="node" id="d5"/>
  <key for="node" id="d6" yfiles.type="nodegraphics"/>
  <key attr.name="Beschreibung" attr.type="string" for="graph" id="d7">
    <default/>
  </key>
  <key attr.name="url" attr.type="string" for="edge" id="d8"/>
  <key attr.name="description" attr.type="string" for="edge" id="d9"/>
  <key for="edge" id="d10" yfiles.type="edgegraphics"/>
  <graph edgedefault="directed" id="G">
    <node id="n0">
      <data key="d4"><![CDATA[http://www.vilauma.de/]]></data>
      <data key="d6">
        <y:ShapeNode>
          <y:Geometry height="30.0" width="30.0" x="785.0" y="-15.0"/>
          <y:Fill color="#FFCC00" transparent="false"/>
          <y:BorderStyle color="#000000" type="line" width="1.0"/>
          <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="18.701171875" modelName="internal" modelPosition="c" textColor="#000000" visible="true" width="45.349609375" x="-7.6748046875" y="5.6494140625">vilauma</y:NodeLabel>
          <y:Shape type="roundrectangle"/>
        </y:ShapeNode>
      </data>
    </node>
  </graph>
</graphml>


Solved my question!

$dom = new DomDocument();
$dom->load("doc.graphml");

$x = new DOMXPath($dom);
$x->registerNamespace("graphml", "http://graphml.graphdrawing.org/xmlns");
$r = $x->query("//graphml:node");

echo $r->length; // result => 1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜