0
<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>

任何知道如何像树一样在网站上显示它们的人:如下所示:

-Apoptosis
--Extrinsic Pathway for Apoptosis
---Death Receptor  Signalling
----FasL/ CD95L signaling
-----FASL...
-----Trimerizaiton of the FASL....
.  .
.  .
.  .
-Signaling pathway

我不知道树有多深,但不会太多。谢谢。

4

2 回答 2

0

查找 PHP 的函数xml_parse_into_struct,您可以使用它将这样的文件拆分为包含适当键的数组。该手册包含您需要的所有信息和示例。

或者,这里有一篇解释如何使用 SimpleXML 的文章。也很容易使用。

于 2013-10-21T03:17:59.107 回答
0

您可以使用支持标准 PHP 树遍历的PHPSimpleXMLIteratorRecursiveIterator

以下示例确实输出了此文本树,例如,它与您在问题中概述的输出类型非常接近:

|-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

这是代码的摘录:

<?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";
}

来自Iterator Garden 的代码在 Github 上可用,这里RecursiveDecoratingIterator使用了。

于 2013-10-21T16:49:29.293 回答