XML文件:
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<DataSources>
    <DataSource Name="ReportDemoConnectionString">
      <ConnectionProperties>
        <ConnectString />
        <DataProvider>SQL</DataProvider>
      </ConnectionProperties>
    </DataSource>
  </DataSources>
  <rd:SnapToGrid>true</rd:SnapToGrid>
  <Body>
    .........
  </Body>
  <DataSets>
    <DataSet Name="dsShowAchievement">
      <Query>
        <CommandText />
        <DataSourceName>ReportDemoConnectionString</DataSourceName>
      </Query>
      <Fields>
        <Field Name="empID">
          <rd:TypeName>System.Int32</rd:TypeName>
          <DataField>empID</DataField>
        </Field>
      </Fields>
    </DataSet>
  </DataSets>
我对这个文件操作,添加一些节点,但最终效果多了一个命名空间,不知道如何处理,以下是操作代码,应该怎样去掉所生成节点中的命名空间呢?XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("XMLFile.xml"));
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace("rt", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
XmlNode nodeDataSet = xmlDoc.SelectSingleNode("rt:Report/rt:DataSets/rt:DataSet[@Name='dsShowAchievement']/rt:Fields", xnm);
XmlElement xe = xmlDoc.CreateElement("Field");
xe.SetAttribute("Name", "testName");
XmlElement sub = xmlDoc.CreateElement("DataField");
sub.InnerText = "testValue";
xe.AppendChild(sub);
nodeDataSet.AppendChild(xe);
xmlDoc.Save(Server.MapPath("XMLFile.xml"));

解决方案 »

  1.   

    生成的结果是这样:
    <Fields>
      <Field Name="empID">
        <rd:TypeName>System.Int32</rd:TypeName>
        <DataField>empID</DataField>
      </Field>
      <Field Name="testName" xmlns="">
        <DataField>testValue</DataField>
      </Field>
    </Fields>多了xmlns=""这个
      

  2.   

    测试下来没有出现你所说的情况using System;
    using System.Collections.Generic;using System.IO;
    using System.Xml;public class Sample
    {
      public static void Main()
      {    XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book ISBN='1-861001-57-5'>" +
                    "<title>Pride And Prejudice</title>" +
                    "</book>");    XmlElement root = doc.DocumentElement;    // Add a new attribute.
        root.SetAttribute("genre", "novel");XmlElement xe = doc.CreateElement("Field");
    xe.SetAttribute("Name", "testName");
    XmlElement sub = doc.CreateElement("DataField");
    sub.InnerText = "testValue";
    xe.AppendChild(sub);root.AppendChild(xe);    Console.WriteLine("Display the modified XML...");
        Console.WriteLine(doc.InnerXml);  }
    }