[英]Display hierarchical xml data in web page
<Pathways species="homo sapiens">
<Pathway dbId="109581" displayName="Apoptosis">
<Pathway dbId="109607" displayName="Extrinsic Pathway for Apoptosis">
<Pathway dbId="73887" displayName="Death Receptor Signalling">
<Pathway dbId="75157" displayName="FasL/ CD95L signaling">
<Reaction dbId="75244" displayName="FASL binds FAS Receptor" />
<Reaction dbId="71050" displayName="Trimerization of the FASL:FAS receptor complex" />
<Reaction dbId="83650" displayName="FasL:Fas binds FADD" />
<Reaction dbId="83586" displayName="FASL:FAS Receptor Trimer:FADD complex binds pro-Caspase-8" />
<Reaction dbId="141310" displayName="FASL:FAS Receptor Trimer:FADD complex binds pro-Caspase-10" />
</Pathway>
</Pathway>
</Pathway>
</Pathway>
<Pathway dbId="109581" displayName="Signaling pathway">
</Pathway>
</Pathways>
Anyone who know how to display them in the website just like a tree: something like below: 任何人都知道如何像在树上一样在网站上显示它们:
-Apoptosis
--Extrinsic Pathway for Apoptosis
---Death Receptor Signalling
----FasL/ CD95L signaling
-----FASL...
-----Trimerizaiton of the FASL....
. .
. .
. .
-Signaling pathway
I don't know how deep for the tree, but not too much. 我不知道这棵树有多深,但不过分。 thanks.
谢谢。
Look up PHP's function xml_parse_into_struct , you use it to split a file like this into an array containing appropriate keys. 查找PHP的函数xml_parse_into_struct ,使用它将这样的文件拆分为包含适当键的数组。 The manual's got all the information and examples you'll need.
该手册包含了您需要的所有信息和示例。
Alternatively, here's an article explaining how to use SimpleXML . 另外, 这是一篇介绍如何使用SimpleXML的文章 。 Pretty easy to use too.
也很容易使用。
You can make use of PHP's SimpleXMLIterator
which does support the standard PHP RecursiveIterator
tree-traversal. 您可以使用PHP的
SimpleXMLIterator
,它确实支持标准的PHP RecursiveIterator
树遍历。
The following example does output this text-tree for example that comes pretty close to the kind of output you've outlined in your question: 下面的示例确实输出了该文本树,例如,它非常接近您在问题中概述的输出类型:
|-Pathway: Apoptosis
| \-Pathway: Extrinsic Pathway for Apoptosis
| \-Pathway: Death Receptor Signalling
| \-Pathway: FasL/ CD95L signaling
| |-Reaction: FASL binds FAS Receptor
| |-Reaction: Trimerization of the FASL:FAS receptor complex
| |-Reaction: FasL:Fas binds FADD
| |-Reaction: FASL:FAS Receptor Trimer:FADD complex binds pro-Caspase-8
| \-Reaction: FASL:FAS Receptor Trimer:FADD complex binds pro-Caspase-10
\-Pathway: Signaling pathway
Here is an excerpt from the code: 以下是代码摘录:
<?php
/**
* Iterator Garden Example
*
* Display hierarchical xml data in web page
*
* @link http://stackoverflow.com/q/19485654/367456
*/
require __DIR__ . '/iterator_garden.php';
$file = __DIR__ . '/data.xml';
$xml = file_get_contents($file);
$it = new SimpleXMLIterator($xml);
$decor = new RecursiveDecoratingIterator($it, function($item) {
return $item['displayName'] ?: $item['species'];
}, RecursiveDecoratingIterator::DECORATE_NODES);
$tree = new RecursiveTreeIterator($decor, RecursiveTreeIterator::BYPASS_CURRENT);
foreach($tree as $key => $item)
{
echo $key, ': ', $item, "\n";
}
The code from Iterator Garden is available on Github , here the RecursiveDecoratingIterator
is used. Github上提供了Iterator Garden的代码,此处使用了
RecursiveDecoratingIterator
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.