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 / .NET Framework / XML / September 2004

Tip: Looking for answers? Try searching our database.

AppendChild adds empty namespace declaration to node

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dorte - 17 Sep 2004 09:21 GMT
Hi,

From an ASP.NET application I am loading an xml-file in order to modify it.
This is part of the code I have produced so far:

XmlDocument XMLDoc = new XmlDocument();

XmlNamespaceManager nsmanager = new XmlNamespaceManager(XMLDoc.NameTable);

nsmanager.AddNamespace("rd",
"http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
nsmanager.PushScope();
nsmanager.AddNamespace("aa",
"http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition" );
   
XmlNode root;
XMLDoc.Load(Server.MapPath("ReportTemplate.xml"));
root = XMLDoc.DocumentElement  ;
System.Xml.XmlNode TableColumns =
root.SelectSingleNode("descendant::aa:TableColumns", nsmanager);
           
XmlElement tablecolumn = XMLDoc.CreateElement("TableColumn");
XmlElement width = XMLDoc.CreateElement("Width");
width.InnerText = "4.0cm";
tablecolumn.AppendChild(width);
TableColumns.AppendChild(tablecolumn);

This however has the disadvantage of adding namespace declarations to the
TableColumn node:
<TableColumn xmlns="">

How can I avoid the empty namespace declaration in the TableColumn node? I'd
prefer not to use the XmlTextWriter instead of DOM, since I need to do quite
a lot of modifications to the XML file.

Thanks for any suggestions.

Dorte
Martin Honnen - 17 Sep 2004 13:11 GMT
> From an ASP.NET application I am loading an xml-file in order to modify it.
> This is part of the code I have produced so far:
[quoted text clipped - 16 lines]
>            
> XmlElement tablecolumn = XMLDoc.CreateElement("TableColumn");

If you want an element to have a namespace you need to specify it e.g.
  XmlElement tablecolumn =
    XMLDoc.CreateElement("TableColumn",
"http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition");

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/


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.