0
PHP의 노드 배열에서 GEXF (http://gexf.net) XML 파일을 자동으로 만들어야합니다.PHP에서 GEXF를 만드는 방법은 무엇입니까?
나는 봤지만 주제를 유용하게 찾을 수 없습니다.
어떻게하면됩니까?
PHP의 노드 배열에서 GEXF (http://gexf.net) XML 파일을 자동으로 만들어야합니다.PHP에서 GEXF를 만드는 방법은 무엇입니까?
나는 봤지만 주제를 유용하게 찾을 수 없습니다.
어떻게하면됩니까?
여기 내 책임입니다. 몇 시간 후에 나는 괜찮아 졌어. 이 예제는 viz : namespace도 지원하므로 더 자세한 노드 요소와 게재 위치를 사용할 수 있습니다.
// Construct DOM elements
$xml = new DomDocument('1.0', 'UTF-8');
$xml->formatOutput = true;
$gexf = $xml->createElementNS(null, 'gexf');
$gexf = $xml->appendChild($gexf);
// Assign namespaces for GexF with VIZ :)
$gexf->setAttribute('xmlns:viz', 'http://www.gexf.net/1.1draft/viz'); // Skip if you dont need viz!
$gexf->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$gexf->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation', 'http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd');
// Add Meta data
$meta = $gexf->appendChild($xml->createElement('meta'));
$meta->setAttribute('lastmodifieddate', date('Y-m-d'));
$meta->appendChild($xml->createElement('creator', 'PHP GEXF Generator v0.1'));
$meta->appendChild($xml->createElement('description', 'by me etc'));
// Add Graph data!
$graph = $gexf->appendChild($xml->createElement('graph'));
$nodes = $graph->appendChild($xml->createElement('nodes'));
$edges = $graph->appendChild($xml->createElement('edges'));
// Add Node!
$node = $xml->createElement('node');
$node->setAttribute('id', '1');
$node->setAttribute('label', 'Hello world!');
// Set color for node
$color = $xml->createElement('viz:color');
$color->setAttribute('r', '1');
$color->setAttribute('g', '1');
$color->setAttribute('b', '1');
$node->appendChild($color);
// Set position for node
$position = $xml->createElement('viz:position');
$position->setAttribute('x', '1');
$position->setAttribute('y', '1');
$position->setAttribute('z', '1');
$node->appendChild($position);
// Set size for node
$size = $xml->createElement('viz:size');
$size->setAttribute('value', '1');
$node->appendChild($size);
// Set shape for node
$shape = $xml->createElement('viz:shape');
$shape->setAttribute('value', 'disc');
$node->appendChild($shape);
// Add Edge (assuming there is a node with id 2 as well!)
$edge = $xml->createElement('edge');
$edge->setAttribute('source', '1');
$edge->setAttribute('target', '2');
// Commit node & edge changes to nodes!
$edges->appendChild($edge);
$nodes->appendChild($node);
// Serve file as XML (prompt for download, remove if unnecessary)
header('Content-type: "text/xml"; charset="utf8"');
header('Content-disposition: attachment; filename="internet.gexf"');
// Show results!
echo $xml->saveXML();
너의 마음을 먹어라! 프로젝트 결과를 이메일로 보내주십시오. 궁금합니다.
GEXF에 대한 lib를 구체적으로 알지는 못하지만, 일반적인 XML 확장을 항상 사용할 수 있습니다. http://stackoverflow.com/questions/188414/best-xml-parser-for-php/3616044#3616044 – Gordon
나는 정말로 내 자신을 쓰는 것을 피하고 싶다. 복잡한 노드 네트워크에서 XML을 구성하는 것이 쉽지 않습니다. – thedp