Hi,
I just tried to replace a single XmlNode with several ChildNodes.
When doing this with the following code i found out that if you get
the ChildNodes with 'ChildNodes' - property the nodes get removed. Is
this possibly a Framework Bug??
foreach( XmlNode node in oldNode.ChildNo des )
{
newNode.AppendC hild( node );
}
parent.ReplaceC hild( newNode, oldNode );
After doing several Tests is tried it the following way and it worked
fine.
[code:1:f2d0f1e0 3d]
for( int i = 0; i < oldNode.ChildNo des.Count; i++ )
{
XmlNode node = oldNode.ChildNo des[ i ];
newNode.AppendC hild( node );
i--;
}
parent.ReplaceC hild( newNode, oldNode );
[/code:1:f2d0f1e0 3d]
Thanks 1 3157
"ason" <sc******@ino de-dot-at.no-spam.invalid> wrote in message news:41******** @Usenet.com... I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes get removed. Is this possibly a Framework Bug??
No, it's a bug in the code example.
foreach( XmlNode node in oldNode.ChildNo des ) { newNode.AppendC hild( node ); } parent.ReplaceC hild( newNode, oldNode );
There are two important facts to realize about this code:
1. foreach uses an IEnumerator. Therefore, if you change the
collection being enumerated, you're going to invalidate the loop's
iterator and it will stop after making the first pass through the
loop's body.
2. XmlNodes have only one ParentNode. When you call AppendChild
you're changing the ParentNode of what was formerly a child node
of oldNode. This means oldNode has one less ChildNode, and new-
Node has one more (i.e., ChildNodes has changed).
After doing several Tests is tried it the following way and it worked fine. [code:1:f2d0f1e0 3d] for( int i = 0; i < oldNode.ChildNo des.Count; i++ ) { XmlNode node = oldNode.ChildNo des[ i ]; newNode.AppendC hild( node ); i--; } parent.ReplaceC hild( newNode, oldNode ); [/code:1:f2d0f1e0 3d]
Did you notice you're incrementing 'i' and then decrementing 'i'
to make this work (again, because the main factor is Append-
Child( ) alters the membership of ChildNodes)?
IEnumerator operates over an IEnumerable, which iterates in
a forward-only manner (IEnumerable has only three members:
Current, MoveNext( ) and Reset( )). As such, a foreach state-
ment can't be expected to go back/forth as you've done in the
for loop above.
Derek Harmon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leszek |
last post by:
Hello,
I have the following code:
// Read the XML document from the hard-drive.
XmlDocument doc = new XmlDocument();
doc.Load("doc.xml");
// Create the document's root.
XmlElement root = doc.DocumentElement;
|
by: Venkat Venkataramanan |
last post by:
Hello:
Can somebody explain to me the usage of the
XMLNode.ChildNodes?
When there is a node that does not have any child node,
the above method returns an array of 1. This member has
the following values:
Name "#text"
|
by: Ken Sturgeon |
last post by:
Using VB.NET in VS2005, assume that you have a RegEx that matches a specific
html tag; for instance "<title>.*?</title>" that returns a match
"<title>SomeTitleHere</title>" and you want to convert that string into an
xmlNode so you can just grab the InnerHTML... how would you go about
converting it to an xmlNode?
My thanks to all respondents in advance for your help.
Ken
|
by: RJN |
last post by:
Hi
I have to read an xml and add the node elements into a hashtable with
nodename as key and nodetext as value. If the selected node has
childnodes, then value should go as an array.
for eg.,
<Root>
<mysection>
|
by: RJN |
last post by:
Hi
I have to read an xml and add the node elements into a hashtable with
nodename as key and nodetext as value. If the selected node has
childnodes, then value should go as an array.
for eg.,
<Root>
<mysection>
| |
by: Claudio |
last post by:
Hi
I'm trying to use XPath queries with streaming XML, but I cannot make
it working.
The solution I'm trying to implement is: create a XmlNode as soon as I
have a full XML element and use the SelectSingleNode method with the
XPath query
Here is a test console application i wrote to better demonstrate my
issue and.. help you help me :)
|
by: =?Utf-8?B?ZGF2aWQ=?= |
last post by:
When I create a tree view control from XML document, I use XmlNode.Name in
the node list iteration. But sometime, it is supposed that it got the element
name. But sometimes it got the element name and first attribute together.
For eaxmple, I use the following iteration code after creating the root from
DOM.DocumentElement.Name.
-----
private void AddNode2(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
|
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= |
last post by:
I'm having the darndest XML config file problem that I really need help with.
I'm supporting a .NET 1.1 desktop application with its own config file, and
I implement IConfigurationSectionHandler so I can have a custom config
section in my config file. The IConfigurationSectionHandler.Create method
just returns the 'section' XmlNode back to the consumer. The config file
looks kind of like this:
<?xml version="1.0" encoding="utf-8" ?>...
|
by: jesper_lofgren |
last post by:
Hello, i need to help here.
I have a xmlnode as you can se below (full xml is in the bottom). I
wonder how i can get the values inside the CSammanstallningLista .
<CSammanstallning Id="Omrade" DefaultInclude="0">
<Rubrik>Område</Rubrik>
<Text>Kallhäll. Fabriksvägen, Hus S, JÄRFÄLLA</Text>
</CSammanstallning>
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |