我正在尝试将xml文件输出为html。看起来simpleXML处理比我的文件上的XSL更快(文件每个2-3mb)。所以我以simpleXML结束。一切似乎都很好,文件加载好$data = simplexml_load_string($file)
但现在我需要用html标签名称替换节点名称,并使用$data->asXML()
构建一个新文档。
有没有办法做到这一点?
我现在拥有的:
<body>
<section>
<title>
<p>sometext</p>
</title>
<epigraph>
<p>sometext</p>
</epigraph>
<stanza>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
</stanza>
<stanza>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
</stanza>
<section>
<title>
<p>sometext</p>
</title>
<epigraph>
<p>sometext</p>
</epigraph>
<stanza>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
</stanza>
<stanza>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
<v>sometext</v>
</stanza>
</section>
</section>
</body>
我想要这个:
<body>
<div class="section">
<h2>
<span>sometext</span>
</h2>
<div class="epigraph">
<p>sometext</p>
</div>
<ul>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
</ul>
<ul>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
</ul>
<div class="section">
<h2>
<span>sometext</span>
</h2>
<div class="epigraph">
<p>sometext</p>
</div>
<ul>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
</ul>
<ul>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
<li>sometext</li>
</ul>
</div>
</div>
</body>
提前致谢
答案 0 :(得分:0)
AFAIK,你不能直接这样做。你可以
foreach
等等strtr($xml, array('stanza>' => 'ul>', 'v>' => 'li>', ...));