我有一个具有这种结构的 HTML 片段:
<li class="level1 item3 parent">
<a href="mainlink.html" class="level1 item3 parent">
<span>
<span class="title">Main title</span>
<span class="sub">Subtitle</span>
</span>
</a>
<ul class="level2">
<li class="level2 item1 first">
<a href="alink.html" class="level2 item1 first"><span>Title 1</span></a>
</li>
<li class="level2 item2">
<a href="alink.html" class="level2 item2"><span>Title 2</span></a>
</li>
<li class="level2 item3">
<a href="alink.html" class="level2 item3"><span>Title 3</span></a>
</li>
<li class="level2 item4 last">
<a href="alink.html" class="level2 item4 last"><span>Title 4</span></a>
</li>
</ul>
</li>
我想把它改成这样:
<li class="level1 item3 parent">
<a href="mainlink.html" class="level1 item3 parent">
<span>
<span class="title">Main title</span>
<span class="sub">Subtitle</span>
</span>
</a>
<ul class="level2">
<li class="level2 item1 first">
<a href="mainlink.html" class="level2 item1 first"><span>Main title</span></a>
</li>
<li class="level2 item1">
<a href="alink.html" class="level2 item2"><span>Title 1</span></a>
</li>
<li class="level2 item2">
<a href="alink.html" class="level2 item3"><span>Title 2</span></a>
</li>
<li class="level2 item3">
<a href="alink.html" class="level2 item4"><span>Title 3</span></a>
</li>
<li class="level2 item4 last">
<a href="alink.html" class="level2 item5 last"><span>Title 4</span></a>
</li>
</ul>
</li>
主要思想是在主 li 元素内的 ul 开头添加一个新项目,克隆部分 a 标签标题该 li 元素。我不知道如何使用 SimpleXML 或 SimpleDOM http://code.google.com/p/simpledom/来完成这项任务......有什么想法吗?
问候,