Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Removing whole Xmlnode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 17 Jun 2007 21:32 GMT
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.
Marc Gravell - 17 Jun 2007 22:38 GMT
Try:
qp.ParentNode.RemoveChild(qp);

Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.