使用xml中的子节点删除节点

时间:2013-05-21 06:39:32

标签: xml vb.net

我遵循XMl格式:

<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Name>TestDoc</Name>
    <Style id="Style1">
      <PolyStyle>
        <fill>0</fill>
      </PolyStyle>
    </Style>
    <Folder>
      <Name>Folder1</Name>
      <Placemark>
        <Name>Placemark1Folder1</Name>
        <LookAt>
          <longitude>-122.0839597145766</longitude>
          <latitude>37.42222904525232</latitude>
        </LookAt>
      </Placemark>
      <Placemark>
        <Name>Placemark2Folder1</Name>
        <LookAt>
          <longitude>-101.083959</longitude>
          <latitude>26.422</latitude>
        </LookAt>
      </Placemark>
    </Folder>
    <Folder>
      <Name>Folder2</Name>
      <Placemark>
        <Name>Placemark1Folder2</Name>
        <LookAt>
          <longitude>-96.566556</longitude>
          <latitude>14.422</latitude>
        </LookAt>
      </Placemark>
    </Folder>
  </Document>
</kml>

我想删除节点内的所有节点及其在vb.net中的所有(节点)子节点.Hence输出Xml应该看起来像:::

<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Name>TestDoc</Name>
    <Style id="Style1">
      <PolyStyle>
        <fill>0</fill>
      </PolyStyle>
    </Style>

  </Document>
</kml> ..

如何实现这一点......提前完成了Thanx ..

1 个答案:

答案 0 :(得分:1)

nod.ParentNode.ParentNode.RemoveChild(nod.ParentNode)

或者你可以尝试

this