473,786 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
<QueryParameter s>
</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.Xml Node.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();
XmlNamespaceMan ager nsmgr = new
XmlNamespaceMan ager(xmlDocumen t.NameTable);
nsmgr.AddNamesp ace("def",
"http://schemas.microso ft.com/sqlserver/reporting/2005/01/reportdefinitio n");

xmlDocument.Loa dXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Report
xmlns=""http://schemas.microso ft.com/sqlserver/reporting/2005/01/reportdefinitio n""
xmlns:rd=""http ://schemas.microso ft.com/SQLServer/reporting/reportdesigner" ">
<DataSources>
<DataSource Name=""DS1"">
</DataSource>
</DataSources>
<DataSets>
<DataSet Name=""Data"">
<Query>
<DataSourceName >DS1</DataSourceName>
<QueryParameter s>
<QueryParamet er Name=""p0"">
<Value>16.06.19 98 0:00:00</Value>
</QueryParameter>
<QueryParamet er Name=""p1"">
<Value>16.06.19 99 0:00:00</Value>
</QueryParameter>
</QueryParameters >
</Query>
</DataSet>
</DataSets>
</Report>");

XmlNode qp = xmlDocument.Sel ectSingleNode(
"//def:QueryParame ters", nsmgr);

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

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

Andrus.
Jun 17 '07 #1
1 3318
Try:
qp.ParentNode.R emoveChild(qp);

Marc

Jun 17 '07 #2

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

Similar topics

2
4609
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
16040
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
8119
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 run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
5
5100
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 xsi:type="a4:Customer+CustomerPayOptions" xmlns:a4="http://schemas.microsoft.com/clr/nsassem/OsfDomain.Resources.Stage/OsfDomain%2C%20Version%3D1.0.0.1%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">cash</PayPerference> I now want to add this XmlNode to a different...
5
2143
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 run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
11
4339
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
1222
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
2981
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 xmlns present is because the Xml I am passing to CRM is a node from a bigger file that does require a xmlns and using the DOM ..OuterXml seems to set the xmlns for you automatically - which I don't want. Any help would be great.
5
7824
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 the actual xml nodes about by interacting with the non-xml TreeView nodes. my basic algorithm is as follows: user has selected a treeview node if user presses Ctrl+Up Arrow, then
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.