471,110 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

AppendChild adds empty namespace declaration to node

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
Nov 12 '05 #1
1 3777


Dorte wrote:

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");


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");

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Manoj G | last post: by

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.