473,434 Members | 1,820 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,434 software developers and data experts.

Remove XMLNamespace from XML Nodes

Hi Everyone

I have an xml document, and for the purposes of my application, I am
going to take a node of the xml (child), add a child to it and then
store it into the database for later use.

So I start with:

<doc xmlns:"http://www.xml.com">
<stuff>
<... />
</stuff>
<child>
<element value="x" />
</child>
</doc>

And want to store:

<child>
<newelement value="w" />
<element value="x" />
</child>

However, because my XmlDocument() is under the given namespace, when I
have created the above node, I am getting the namespace attributed to
it like so:

<child xmlns="http://www.xml.com">
<newelement value="w" xmlns="" />
<element value="x" />
</child>

Is there any way I can stop this from happenening, because later on in
the process, the XmlNode will be appended to an XmlDocument under this
namespace.

Many thanks

Darren

Jun 6 '06 #1
2 4092


daz_oldham wrote:
However, because my XmlDocument() is under the given namespace, when I
have created the above node, I am getting the namespace attributed to
it like so:

<child xmlns="http://www.xml.com">
<newelement value="w" xmlns="" />
<element value="x" />
</child>

Is there any way I can stop this from happenening, because later on in
the process, the XmlNode will be appended to an XmlDocument under this
namespace.


An element or attribute node gets its namespace at creation time and it
does not change later when you insert the node somewhere. Thus if you
want to create an element in the namespace http://example.com/2006/xml
then you need to use a namespace aware creation method e.g.
XmlElement newElement = xmlDocument.CreateElement("newelement",
"http://example.com/2006/xml");

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 6 '06 #2
Will this have an effect later on when I use the child, because for the
purposes of what I am doing, I ideall don't want to keep the namespace
information.

If it is that re-specifying the namespace more than once won't cause a
problem, then I should be okay... however if it is, then I am going to
have a problem with my validation.

(if it helps, i'm a bit of a novice at xmldom etc)

I will in effect end up with something like this:

<root xmlns="http://x.com" >
<otherdata>
<nodes>...</nodes>
<child>
<savednode xmlns="http://x.com">
<childnode xmlns="" />
<savednode>
<savednode xmlns="http://x.com">
<childnode xmlns="" />
<savednode>
<savednode xmlns="http://x.com">
<childnode xmlns="" />
<savednode>
</child>
</root>

Many thanks for your help Martin - what do you think?

Darren
Martin Honnen wrote:
daz_oldham wrote:
However, because my XmlDocument() is under the given namespace, when I
have created the above node, I am getting the namespace attributed to
it like so:

<child xmlns="http://www.xml.com">
<newelement value="w" xmlns="" />
<element value="x" />
</child>

Is there any way I can stop this from happenening, because later on in
the process, the XmlNode will be appended to an XmlDocument under this
namespace.


An element or attribute node gets its namespace at creation time and it
does not change later when you insert the node somewhere. Thus if you
want to create an element in the namespace http://example.com/2006/xml
then you need to use a namespace aware creation method e.g.
XmlElement newElement = xmlDocument.CreateElement("newelement",
"http://example.com/2006/xml");

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Jun 6 '06 #3

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

Similar topics

2
by: Claudio Jolowicz | last post by:
How can XSLT stylesheets be used to edit, remove and add nodes specified by their position in the document tree? The XML document stores development tasks in a hierarchical way, i.e. tasks can...
6
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal"...
8
by: Mikey | last post by:
I have an XML document as follows: <Menu> <Group> <Item Text="About Us" AccessRoles="All"> <Group> <Item Text="Option 1" AccessRoles="All" /> <Item Text="Option 2" AccessRoles="All" /> <Item...
2
by: fizzy | last post by:
i am fetching an xml document with the following structure: <?xml version="1.0" encoding="UTF-8"?> <DTCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
0
by: aredo3604gif | last post by:
I have coded a serie of singly linked lists in ANSI C which I have to use. The lists are then stored in a serie of buckets with chained hash table technique. In the various lists there are nodes...
3
by: Markus | last post by:
Hi! I wanted to select a subset of nodes (list = selectNodes("parent/child") from a XmlDocument, then remove all (parentNode.removeAll();) child-nodes and insert the previous selected nodes...
1
by: Boni | last post by:
Dear all, I have a tree node inherited from TreeNode class. Sometimes when I call Nodes.Clear() I get following exception. I use .NET 2.0.50727. Seems to be MS bug? Any ideas? Thanks Boni ...
4
by: crmpicco | last post by:
I am trying to delete all 'PiccoOption' nodes that i do not need, i then want to put the document, with just one 'PiccoOption' into the form field 'document.form.optionNumber.value'. This code...
11
by: David | last post by:
Hi All, I am working on a script that is theoreticaly simple but I can not get it to work completely. I am dealing with a page spit out by .NET that leaves empty tags in the markup. I need a...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.