0
A
回答
3
這是我對此的看法。幾個小時後,我明白了。這個例子也支持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();
吃你的心臟了!隨意給我發電子郵件您的項目結果,我很好奇。
相關問題
- 1. 如何從一組.csv工作表創建一個.gexf文件?
- 2. 如何創建PHP
- 3. 如何從MySQL列創建php數組?
- 4. 如何創建從PHP選擇
- 5. 如何從Mysql創建PHP數組
- 6. 如何從PHP數組創建HTML表?
- 7. 創建PHP從URL
- 8. 從php創建CSV
- 9. 如何使用PHP創建
- 10. 如何用PHP創建
- 11. 如何在PHP中創建
- 12. 如何在PHP中創建
- 13. 如何創建用PHP
- 14. 如何在PHP中創建
- 15. PHP如何從文件中創建php頁面
- 16. 如何從另一個php數組創建php哈希數組?
- 17. 如何使用php創建php文件
- 18. 如何使用php創建.php文件?
- 19. SigmaJS輸出圖爲GEXF
- 20. PHP創建從當月
- 21. PHP - 動態創建從SQL
- 22. 創建MySQL用戶從PHP
- 23. 從PHP創建的HTML
- 24. 從PHP創建插件域
- 25. PHP - 創建一個從
- 26. 從MySQL創建PHP數組
- 27. 從php創建表格
- 28. 從PHP創建LESS變量
- 29. 從php創建html頁面
- 30. 從PHP API創建REST API
我並不知道GEXF的任何lib,但您可以隨時使用任何通用的XML擴展,例如http://stackoverflow.com/questions/188414/best-xml-parser-for-php/3616044#3616044 – Gordon
我真的想避免寫我自己的。從複雜的節點網絡構建這樣的XML並不容易。 – thedp