473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 3886


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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.