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

Weird Issue XML AppendChild

Can you not append a XmlWhiteSpace node to XmlDocument?

See example:

using System;
using System.Xml;

class TestXml
{
public static void Main(string[] args)
{
string xmlDoc = @"<root><child>a</child></root>";

string newXml = @"
<child>b</child>
<child>c</child>
";

XmlDocument d = new XmlDocument();
d.LoadXml(xmlDoc);

XmlElement tmpNode = d.CreateElement("newNodes");
tmpNode.InnerXml = newXml;

//there are 5 nodes, 2 Elements
Console.WriteLine("Number of nodes: " + tmpNode.ChildNodes.Count);
int i = 0;
foreach(XmlNode n in tmpNode)
{
//HMM: should run 5 times right since tmpNode has 5 children but only
runs once!?
//HOWEVER, if you simply add NON-whitespace nodes, it'll work correctly
Console.WriteLine("NODE: " + i++ + ", " + n);
//now append the child node
d.AppendChild(n);
}

}
}
Nov 12 '05 #1
3 2295
anonymous wrote:
foreach(XmlNode n in tmpNode)


Should it be foreach(XmlNode n in tmpNode.ChildNodes) ?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg-
No difference if you change it.

And..If you change

-->foreach(XmlNode n in tmpNode)

to:

-->foreach(XmlNode n in tmpNode)
{
if(n.NodeType != XmlNodeType.Element) continue;

Still NO GO.

However, this works:

-->foreach(XmlNode n in tmpNode.SelectNodes("//child") )
Truly baffled... or stupid. Probably the latter.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
anonymous wrote:
foreach(XmlNode n in tmpNode)


Should it be foreach(XmlNode n in tmpNode.ChildNodes) ?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
anonymous wrote:
Oleg-
No difference if you change it.

And..If you change

-->foreach(XmlNode n in tmpNode)

to:

-->foreach(XmlNode n in tmpNode)


Hmm, both your strings are equal. I meant that's weird to iterate over a
single node. Most likely you want to iterate over tmpNode's childrens?

foreach(XmlNode n in tmpNode.ChildNodes)

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4

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

Similar topics

2
by: Martin Doyle | last post by:
Ok, I'm building a JS-based limitless-sublevel dynamic menu and am making it cross browser as well - 3 packs of aspirin so far and counting ;) I'm having a weird rendering problem using Opera...
6
by: Scott | last post by:
The code below appears to work on the following: MAC - Safari PC - IE PC - Opera But the addition of items to the dropdown (select2) does not function in: MAC – IE
14
by: nickdevx | last post by:
Without knowing "html before" and "html after" can anyone fathom any reason why the following code crashes IE but if I add <br/> after ANY <input> tags it doesn't? ...
8
by: william_dean | last post by:
Hello, I've done some searching around the post, and I have found quite a bit of information related to the setAttribute and it's related uses. My problem lies in the usage of colspanning in dynamic...
6
by: daveyand | last post by:
Hey Guys, I've stumped. I created a function that does various things to select boxes. Namely Get All selected indexes, populate array with these values
2
by: rpfromuk | last post by:
Hi everyone, I am having an issue with using document.createElement in IE (at least I think that's what the problem is). The following code snippet works in FireFox no problem, but doesn't show...
2
by: junal | last post by:
hey guess ....im having some problem with my browser. my script runs well in FF but it saisy object null in IE....plz can anybody see this code and tell me where i did make mistake ? here im trying...
1
by: saikatbose2005 | last post by:
Hi, Ineed some help from anyone regarding an issue I'm facing. I've created an image dynamically on clicking a button. What I inetend to do is when I click on the created image it will popup a...
1
by: Gregor Kofler | last post by:
Sytse meinte: Please stop top-posting. Thanks. Easy: Don't use document.write() after loading a page. Why do you write at all? Apend anchor elements to the body in your create()-function.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
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
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
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.