Removing whole Xmlnode

A

Andrus

How to remove whole Xmlnode so that outer tags are also removed ?

To reproduce, run the code.

Observed result:

<Query>
<DataSourceName>DS1</DataSourceName>
<QueryParameters>
</QueryParameters>
</Query>

Expected result:

<Query>
<DataSourceName>DS1</DataSourceName>
</Query>

How to get expected result ?

I tried

qp.OuterXml = "";

but got error

Property or indexer 'System.Xml.XmlNode.OuterXml' cannot be assigned
to -- it is read only

Code to reproduce:

using System;
using System.IO;
using System.Xml;
class test {

public static void Main() {

XmlDocument xmlDocument = new XmlDocument();
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("def",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");

xmlDocument.LoadXml(@"<?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=""DS1"">
</DataSource>
</DataSources>
<DataSets>
<DataSet Name=""Data"">
<Query>
<DataSourceName>DS1</DataSourceName>
<QueryParameters>
<QueryParameter Name=""p0"">
<Value>16.06.1998 0:00:00</Value>
</QueryParameter>
<QueryParameter Name=""p1"">
<Value>16.06.1999 0:00:00</Value>
</QueryParameter>
</QueryParameters>
</Query>
</DataSet>
</DataSets>
</Report>");

XmlNode qp = xmlDocument.SelectSingleNode(
"//def:QueryParameters", nsmgr);

// Property or indexer 'System.Xml.XmlNode.OuterXml' cannot be assigned
// to -- it is read only:
// qp.OuterXml = "";

// this does not reove whole node !
qp.RemoveAll();
xmlDocument.Save(Console.Out);
}
}

Andrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top