By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

Removing whole Xmlnode

P: n/a
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.
Jun 17 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Try:
qp.ParentNode.RemoveChild(qp);

Marc

Jun 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.