我有:
<nodes>
  <node>
    <name>node1</name>
    <other>stuff1</other>
    <node>
      <name>node11</name>
      <other>stuff11</other>
    </node>
    <node>
      <name>node12</name>
      <other>stuff12</other>
    </node>
  </node>
  <node>
    <name>node2</name>
    <other>stuff2</other>
  </node>
  <node>
    <name>node3</name>
    <other>stuff3</other>
  </node>
</nodes>
我想最终得到一个平面结构,如:
<nodes>
  <node>
    <name>node1</name>
    <other>stuff1</other>
  </node>
  <node>
    <name>node11</name>
    <other>stuff11</other>
  </node>
  <node>
    <name>node12</name>
    <other>stuff21</other>
  </node>
  <node>
    <name>node2</name>
    <other>stuff2</other>
  </node>
  <node>
    <name>node3</name>
    <other>stuff3</other>
  </node>
</nodes>
这是一个简单的示例,但我想复制每个节点中的所有元素,而不是嵌套的“节点”元素。我尝试复制以保留标签,但也保留了嵌套。我也尝试过复制,但忽略了所有孩子。
有任何想法吗?