首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

XML父节点有关问题,玩的熟的哥们儿看看

2013-12-13 
XML父节点问题,玩的熟的哥们儿看看?xml version1.0 encodingutf-8?bookstorebook genreee I

XML父节点问题,玩的熟的哥们儿看看

<?xml version="1.0" encoding="utf-8"?>
<bookstore>
  <book genre="ee" ISBN="2-3631-4">
    <title>三国演义</title>
    <author>lfdfd</author>
    <price>55.95</price>
  </book>
  <book ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>涨红</author>
    <price>58.3</price>
  </book>
  <book genre="计算机" ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>
  <book genre="计算机" ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>
</bookstore>

想把<bookstore></bookstore>这层节点删除掉,怎么实现下面效果:

<?xml version="1.0" encoding="utf-8"?>
  <book genre="ee" ISBN="2-3631-4">
    <title>三国演义</title>
    <author>lfdfd</author>
    <price>55.95</price>
  </book>
  <book ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>涨红</author>
    <price>58.3</price>
  </book>
  <book genre="计算机" ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>
  <book genre="计算机" ISBN="2-3631-4">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>

[解决办法]

    string xml=@"
            <?xml version=""1.0"" encoding=""utf-8""?>
<bookstore>
  <book genre=""ee"" ISBN=""2-3631-4"">
    <title>三国演义</title>
    <author>lfdfd</author>
    <price>55.95</price>
  </book>
  <book ISBN=""2-3631-4"">
    <title>CS从入门到精通</title>
    <author>涨红</author>
    <price>58.3</price>
  </book>
  <book genre=""计算机"" ISBN=""2-3631-4"">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>
  <book genre=""计算机"" ISBN=""2-3631-4"">
    <title>CS从入门到精通</title>
    <author>盖茨</author>
    <price>58.3</price>
  </book>
</bookstore>

";
        xml = Regex.Replace(xml, @"\<.{0,1}bookstore\>", "");

热点排行