472,811 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 3866


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
7
by: Robert Oschler | last post by:
I'm having a very painful time converting some Mozilla dynamic DOM code to work with Internet Explore. For example, given this code: -------------- selectBox=document.createElement("SELECT");...
6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
5
by: SenthilSS | last post by:
My application produces XML Data files which have XML namespace qualified XML elements (nodes), but the namespace itself is not declared in the data file. My task is to read these data files in a...
2
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
2
by: Simon_Keep | last post by:
Hi, I have an Xslt extension object that returns a node-set to the xslt stylesheet which then uses an xsl:copy-to statement to write it to the output. The problem I am having is that the...
8
by: Simon Brooke | last post by:
I was debugging a new XML generator tonight and trying to determine why it wasn't working; and realised my dom printer does not output XML namespace declarations. My method to output an Element...
3
by: Fede | last post by:
Hi everybody, in vb.net I have this code: ...... myNode= XmlDoc.CreateElement("aNode") myAttribute = XmlDoc.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink") ...
1
by: dignan.tenenbaum | last post by:
Hello, I'm using the XmlReader.ReadOuterXml() method to return the string representation of an xml node. The XmlReader is created with a file path and a XmlReaderSettings object. This was...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.