473,806 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing nodes without namespace

Hi, I'm having trouble with namespaces when importing nodes. I'd like to get
this output:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" />
<row Lsm_Info="DEF45 6" />
</exampleRoot>

But instead I'm getting:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" xmlns="" />
<row Lsm_Info="DEF45 6" xmlns="" />
</exampleRoot>

This is the code I'm using:

XmlReader reader = command.Execute XmlReader();

XmlElement rootNode = xmlDocument.Cre ateElement("exa mpleRoot ",
http://mynamespace);
xmlDocument.App endChild(rootNo de);

reader.MoveToCo ntent();
XmlNode readerNode = xmlDocument.Rea dNode(reader);

while (readerNode != null)
{
XmlNode importNode = xmlDocument.Imp ortNode(readerN ode, false);

xmlDocument.Doc umentElement.Ap pendChild(impor tNode);

readerNode = xmlDocument.Rea dNode(reader);
}

How do I get rid of the xmlns=""? Any help is much appreciated!

Cheers,
Chris
Nov 21 '05 #1
5 10360


Christoffer wrote:
Hi, I'm having trouble with namespaces when importing nodes. I'd like to get
this output:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" />
<row Lsm_Info="DEF45 6" />
</exampleRoot>

But instead I'm getting:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" xmlns="" />
<row Lsm_Info="DEF45 6" xmlns="" />
</exampleRoot>


A node is not changed when it is imported or cloned thus if those row
elements you are importing are in no namespace then the serialization is
correct, an element in no namespace which is a child of an element
declaring a default namespace needs to be serialized with xmlns="" to
make sure the markup undeclares the namespace.

If you want to have elements in a different namespace then importNode
does not help, you need to create the new elements in the desired namespace.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '05 #2
"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

Christoffer wrote:
Hi, I'm having trouble with namespaces when importing nodes. I'd like to
get this output:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" />
<row Lsm_Info="DEF45 6" />
</exampleRoot>

But instead I'm getting:

<exampleRoot xmlns="http://mynamespace">
<row Lsm_Info="ABC12 3" xmlns="" />
<row Lsm_Info="DEF45 6" xmlns="" />
</exampleRoot>


A node is not changed when it is imported or cloned thus if those row
elements you are importing are in no namespace then the serialization is
correct, an element in no namespace which is a child of an element
declaring a default namespace needs to be serialized with xmlns="" to make
sure the markup undeclares the namespace.

If you want to have elements in a different namespace then importNode does
not help, you need to create the new elements in the desired namespace.


So the "row" elements/nodes which I get from the XmlReader have to be
re-created? I can not simply change their namespace?

Cheers,
Chris
Nov 21 '05 #3


Christoffer wrote:
So the "row" elements/nodes which I get from the XmlReader have to be
re-created? I can not simply change their namespace?


You cannot change the namespaceURI of nodes in the DOM implemented in
..NET 1.x and 2.0.
The W3C DOM Level 3 suggests a method named RenameNode on XML document
objects but .NET does not implement the W3C DOM Level 3, only level 2
(and lots of Microsoft extensions like InnerXml/OuterXml).

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '05 #4
"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..

Christoffer wrote:

You cannot change the namespaceURI of nodes in the DOM implemented in


Basically, it can't be done without loads and loads of work right?

Is there a way to get the StartElement and EndElement from an XmlElement? In
that case I could create the xml element and then build a string instead of
using XmlDocument.

For example,

string xmlRows = command.Execute Scalar() as string;
XmlElement rootNode = xmlDocument.Cre ateElement("exa mpleRoot ",
"http://mynamespace");
StringBuilder build = new StringBuilder() ;
build.Append(ro otNode.StartEle ment);
build.Append(xm lRows);
build.Append(ro otNode.EndEleme nt);

That would, in theory, create the result I'd like to get...

Cheers,
Chris
Nov 21 '05 #5


Christoffer wrote:
"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Christoffer wrote:

You cannot change the namespaceURI of nodes in the DOM implemented in

Basically, it can't be done without loads and loads of work right?


It can be done with a few lines of code, as said if you have DOM nodes
you just need to make sure you create the same nodes with the desired
namespace(s). As only element nodes and attribute nodes can be in a
namespace you have to write code for those two node types, for all other
nodes you can clone/import/copy as usual.
However you have XmlReader you start with so there it might not make
sense to first use ReadNode to create DOM nodes and then rework the DOM
with CreateElement but to implement an extension of XmlTextReader that
simply changes the namespace(s) as needed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '05 #6

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

Similar topics

5
5279
by: Adam Barr | last post by:
I have a tag foo that I want to copy unchanged when it is a subtag of bar, so I have a template (x is the namespace for the document): <xsl:template match="x:bar/x:foo"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> BUT, I discovered that someone has been mis-speling foo as foop in the
1
2238
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse some of these master complex and simple types. This I believe will assist me in transforming between the master schema and the other smaller schemas that contain a subset of the elements in the master schema. I understand that I can import an...
6
3523
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" and "ns0:Company" but I do not want to delete their child nodes("w:p","w:r","w:t"). How can I do this? <ns0:Proposal> <ns0:Company> <w:p> <w:r>
2
10704
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
29
4251
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Caching;
0
861
by: google | last post by:
Hi, I currently have a .net page default.aspx - as so: <%@ Page Inherits="webmail.telnet_test" Src="./mail_code/telnet.cs" Trace="true" Language="C#" %> <html> <head>
2
4108
by: daz_oldham | last post by:
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>
3
4141
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(str); request.Credentials = System.Net.CredentialCache.DefaultCredentials;
3
1378
by: thesmithman | last post by:
Howdy folks, My XML file contains the contents of several web pages. Example: <allPages> <thisPage> <h1>Page Title</h1> <p>Some text, which contains an <a href="link.php">inline link.</a></p>
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.