473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Removing whole Xmlnode

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
1 3293
Try:
qp.ParentNode.RemoveChild(qp);

Marc

Jun 17 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: GhislainTanguay | last post by:
This is my XML file and below you will find my code to remove it... I was thinking that it's a simple task but this code doesn't work. Anybody have a better solution? <Advertisements>
3
by: e-mid | last post by:
Here is an xml structure. i want to remove <a> nodes that do not have any child. How can i do that in csharp? <root> <a> <b/> </a> <a/> <a/> <a> <c/>
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
11
by: EAI | last post by:
Hi All, I have a XML of the following form <?xml version="1.0"?> <xxxx xmlns="http://xxx.xxx.com"> .... </xxxx> When I try to read xml using SelectSingleNode, I am getting exception
3
by: GhislainTanguay | last post by:
This is my XML file and below you will find my code to remove it... I was thinking that it's a simple task but this code doesn't work. Anybody have a better solution? <Advertisements>
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
5
WebDunce
by: WebDunce | last post by:
Hi guys, I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.