473,406 Members | 2,954 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,406 software developers and data experts.

get rid of blank namespaces

Hello

I'm using c# XmlDocument class to add new XHTML-Nodes to my website.
Unfortunately XmlDocument always adds an unwanted empty namespace attribute
xmlns="" to every new Element.
These empty namespace attributes cause that the elements are'nt found any
more when I'm reparsing the document. (When I delete them by hand everything
works fine).
This is really stupid. DotNet XML-classes aren't very useful for me if I
can't affect their behaviour.
XmlSerializer seems to have the same problem.

Isn't there any hack to bypass the blank namespaces???

Thank you
Sincerely
Lore

******************* code ***************************
//doc is a loaded XmlDocument object
XmlElement paragraph = doc.CreateElement("p");
paragraph.SetAttribute("class","paragraph");

XmlElement imgNode = null;
if(pctEntry.Image != null)
{
imgNode = doc.CreateElement("img");
imgNode.SetAttribute("src",pctEntry.Tag.ToString() );
imgNode.SetAttribute("alt",txtAlt.Text);
paragraph.AppendChild(imgNode);
}
//text
if(txtEntry.Text.Trim() != "")
{
string tmp = ToXHTML(txtEntry.Text);
XmlText textNode = doc.CreateTextNode(tmp);
paragraph.AppendChild(textNode);
}
XmlNode node = doc.SelectSingleNode("//xl:div[@ id='content']",
namespaceManager);
if(node != null)
node.AppendChild(paragraph);
Apr 19 '06 #1
2 2146


Lore Leunoeg wrote:

I'm using c# XmlDocument class to add new XHTML-Nodes to my website.
Unfortunately XmlDocument always adds an unwanted empty namespace attribute
xmlns="" to every new Element.


If you want to create elements in the XHTML 1 namespace with URI
http://www.w3.org/1999/xhtml with the DOM then of course you need to use
namespace aware methods and pass in the right namespace e.g. with that
DOM code

XmlDocument xmlDocument = new XmlDocument();
const string xhtml1NamespaceURI = "http://www.w3.org/1999/xhtml";
xmlDocument.AppendChild(xmlDocument.CreateElement( "html",
xhtml1NamespaceURI));

xmlDocument.DocumentElement.AppendChild(xmlDocumen t.CreateElement("head",
xhtml1NamespaceURI));

xmlDocument.DocumentElement.AppendChild(xmlDocumen t.CreateElement("body",
xhtml1NamespaceURI));
xmlDocument.Save(Console.Out);

the result is

<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body />
</html>

So make sure _when_ you create an element you pass in the right
namespace URI to CreateElement as the namespace a node belongs to is
determined when the node is created and not when/where it is inserted later.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 20 '06 #2
Mmh. Thank you.
Seems I'm a little dull with namespaces.
Thank you again.
Sincerely
Lore
Apr 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
7
by: beachdog | last post by:
I'm using Visual Studio 2005/C# to build a web client. The web server is something I've written in a different framework, which does not support generating wsdl, so I have hand-built a wsdl file,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.