XmlNode.ChildNodes Bug????

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.ChildNodes )
{
      newNode.AppendChild( node );
}
parent.ReplaceChild( newNode, oldNode );


After doing several Tests is tried it the following way and it worked
fine.
[code:1:f2d0f1e03d]
for( int i = 0; i < oldNode.ChildNodes.Count; i++ )
{
      XmlNode node = oldNode.ChildNodes[ i ];
      newNode.AppendChild( node );
      i--;
}
parent.ReplaceChild( newNode, oldNode );
[/code:1:f2d0f1e03d]

Thanks

0
schiller (1)
9/23/2004 9:03:42 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
719 Views

Similar Articles

[PageSpeed] 18

"ason" <schiller@inode-dot-at.no-spam.invalid> wrote in message news:4152916e_5@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.ChildNodes )
> {
>       newNode.AppendChild( node );
> }
> parent.ReplaceChild( 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:f2d0f1e03d]
> for( int i = 0; i < oldNode.ChildNodes.Count; i++ )
> {
>       XmlNode node = oldNode.ChildNodes[ i ];
>       newNode.AppendChild( node );
>       i--;
> }
> parent.ReplaceChild( newNode, oldNode );
> [/code:1:f2d0f1e03d]

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


0
loresayer (274)
9/26/2004 2:27:59 AM
Reply:

Similar Artilces:

BUG: COleSafeArray has a bug in its GetByteArray
BUG: COleSafeArray has a bug in its GetByteArray From: John Brumbelow To whom it may concern, I have found a bug. I'm using VS.NET 2003 as such: Microsoft Visual C++ .NET 69586-335-0000007-18276 The source for COleSafeArray is coded to use the SafeArrayGetLBound and SafeArrayGetUBound as if the index passed in for the 1nd parameter was 0 based, where the documentation for SafeArrayGetLBound/SafeArrayGetUBound "evidently" require the parameter to be 1 based. The MSDN documentation for SafeArrayGetLBound does give a sample iterating the 1 based "bias", but that ...

Bugs?
Hi, Why does Outlook "receive" the same email twice? When I get mail on a pop3 account it seems to want to download it twice. Most annoying! I leave Outlook running it downloads incomming mail as expected. When I reboot and run Outlook again it will download already downloaded email. And secondly when I quit Outlook it frequently asks me if I want to save over the normal template. Obviously this is coming from Word but Outlook may have something to do with the problem. I'm using Word as the email editor. I have Outlook 2003 running on Windows XP. Any help or suggestio...

ASP problem: is this a bug in VBScript?
I'm running a web server with vbscript 5.8 I have the following problem: I define a class, put the instances into an array, and write this array into the Session instance. When getting back the array, there are still objects in it, but VBScript seems to forget the type of object. Is this a bug in the object serialisation? The code is: <%@ LANGUAGE="VBSCRIPT" %> <% OPTION EXPLICIT %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> </head> <body> <% class test public txt end clas...

XmlNode
When an XmlNode method returns an XmlNode, such as a child, is this generated on-the-fly or is it the actual component of the internal tree structure? If the parent is moved in the tree, will the pointer remain valid? I have looked at as much of the structure as I can using .NET Reflector and I think it will, but I want to be sure. I 'm planning to add XmlNodes to the Tag property of TreeNodes in a TreeView to be able to persist changes back to the document and I would like to know if this will take up any more memory than when they are not linked in this way, or if it is better to...

Word 2010 bugs
There are lots of bugs in Word 2010 from previous versions. For example, if you select part of a table and get the word count, the word count for the entire document is returned. This is a bug introduced in Word 2007. Is it worth reporting these bugs? I have spent hours documenting and sending in reports, but nothing gets fixed. They really slow down my productivity, but it seems Microsoft isn't interested in fixing them, so perhaps "beta testing" is just a waste of time. Benjamin Barrett It is not worth reporting the bugs here - you need to feedback to the a...

POS 2009 Workorder tender Issue (BUG)
Hi There Not sure if its only me or has someone else faced the same problem as me. I feel there is a big or something wrong. The Scenario is: 1) Create a work order 2) F12 to sav work order and take deposit 3) Choose payment type (lets say Debit Card) ---> At this point cant save or tender this work order. Wouldnt allow me to select Debit card for work order. ---> Tried on Cash and it goes through ---> Checked my settings. The only difference is Cash was setup as payment format cash and Debit Card was setup as payment format Other. --> Changed Cash to payment format other ...

Bug with outlook 2003
Hello, I've got a little problem with outlook 2003 and exchange 2003. When I want to change contact parameters like Tools - Option - Contact option - change contact sort I've got the following message : Faulting application outlook.exe, version 11.0.5510.0, stamp 3f1380f0, faulting module user32.dll, version 5.1.2600.2622, stamp 4226019c, debug? 0, fault address 0x000529a6. have you got an idea ? Thank's for all Regard's Jean Marie try detect and repair first, it's on the help menu. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hou...

Excel 2007 chart text box bug
Just found what looks like a bug with charts in Excel 2007. In Excel 2003 I could add a text box to a chart and then assign a formula to it, say =B30. The value in B30 would then appear in the text box. If I insert say 5 rows and three columns above B30, the fomula would adjust and become =E35. When I do the same in Excel 2007, the formula for the box says as =B30 The workaround is to use range name, ie, =rangename. However, that adds lots of extra steps. And users have to know to do and know that Excel 2007 behaves differently. No logic in the change, so it most likely is a bug. ...

xmlNode.InnerText vs. xmlNode.Value
I've loaded the following xml into an XMLDocument object: <?xml version="1.0" ?> - <Preferences> <Institution>Argh</Institution> <Speaker>Chigier, Ben (1234)</Speaker> <Worktype>Addendum</Worktype> <speakerCode>1234</speakerCode> </Preferences> I then try to retrieve the value of the Institution node as follows: string s = myxmldoc.SelectSingleNode("/Preferences/Institution").Value; However, s is null after the call. But if I change the call to the following, s is what I'd expect: "A...

Large integers in excel 2003 are rounded ?? Is this a BUG ?
Format a cell as number and set decimal places to 0. Then enter 1818181818181818 in a cell and hit enter... Excel then CHANGES to the number to: 1818181818181810 ???? WHAT ??? This can't be right can it ??, what am I missing ? I just tried it and Excel did the same thing. Looks odd. I removed all formatting though and the number changed to scientific notation 1.81818E+15 Probably some quirk with the number being so large. You might want to explore Microsoft's Knowlege base on this. "Mike One" wrote: > Format a cell as number and set decimal places to 0. &...

How to get the XML path of an XmlNode?
How can I get the full XML path (as string) of a specific XmlNode ? -- Thanks Sharon Sharon wrote: > How can I get the full XML path (as string) of a specific XmlNode ? What is "the full XML Path" of a node, do you have any definition for that? Some XML editors can assist you constructing or maybe even generating an XPath expression. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ Lets say I have the following XML file: <?xml version="1.0" encoding="utf.8"?> <System Name = "System"> <Parameters> <T1&...

Typpgrphic bug in Office 2004 Entoruage and Word
> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3274168687_18294638 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: 8bit I have noticed that when I type a contraction eg. Don'to, can'to, won�to I get a trailing o. I can�t make this stop. What is causing this? OSX 10.4.1 Entourage Version 11.3.6 Word Version 11.3.5 --B_3274168687_18294638 Content-type: text/html; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable <...

XmlSerialization to XmlNode
I have a schema that I load into classes that mirror the schema using the XmlSerialization. The schema contains an xsd:Any that I load into 'Extra' as follows: [XmlElement(ElementName="Extra")] public XmlNode Extra { get { return extra;} set { extra = value;}} However, if I have: <Something> <Extra> <a>something</a> <b>another thing</b> </Extra> </Something> I would expect Extra to contain an XmlNode of : <Extra> <a>something</a> <b>another thing</b> <...

Dynamic Picklist bug
I've installed the Dynamic Picklist from the CRM 3.0 SDK. I've installed it directly as well as created a separate entity and re-created it there and copy/pasted edited Jscript into the new entity so that it works with my field names and my drop-down picklist items. They both work just fine (the original default test entity as well as my edited entity) with one fairly major bug. On either entity when you select your Industry it pulls the correct index for subindustry and displays these for the user to select from. When the user selects the desired Sub-industry, it indeed ent...

Problem with XmlNode.ChildNodes across different machines
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" ?> <configuration> <configSections> <section name="MyConfigSettings" type="MyAssembl...

Bug Reports
Does MS have any mechanism for submitting bug reports for Word? http://connect.microsoft.com -- -Ben- Ben M. Schorr, MVP Roland Schorr & Tower http://www.rolandschorr.com http://www.officeforlawyers.com/word.htm Author - The Lawyer's Guide to Microsoft Word 2007: http://tinyurl.com/abaword2007 <faceman28208@yahoo.com> wrote in message news:4b95a113-bc00-4bb5-8dc1-bfcabe34981e@r24g2000yqd.googlegroups.com... > Does MS have any mechanism for submitting bug reports for Word? On Nov 29, 2:57=A0pm, "Ben M. Schorr, MVP" <b...@bogusaddress.mv...

How to report outlookg bug
I want to report a bug in outlook. How should I do this. Thanks Minhaj ...

Keyboard event bug on 64bit systems
Hi, I have an application that contains the fix described in http://support.microsoft.com/kb/187988. It also uses an ActiveX control that contains the fix described in http://support.microsoft.com/kb/233263. When this application is installed on a 64bit system and certain dialogs are open, keyboard events are received multiple times. So instead of "1" appearing in an edit box "1111" appears. This problem does not appear when the application is run on a 32bit system. I have created a small contrived example that exhibits the same behavior. Here is how to do it: * C...

Edit Item changes Prices bug
Hello all, I have some problem with I just added store to my RMS HQ about a month ago. The version I got this time is 1.3.1002. both HQ and StoreOp While I was using it up I found that the version I got was not the latest one and have a very serious bug. The problem is this. It changes price of item when I open another edit item window without closing the one before. It does it when I diable the price chaning privillege. I found this out after entering close to 9000 items. All the prices are quite messed up thanks to our staffs weird habit of clicking without thinking. I contacted MS a...

how to transform escaped xml contents in xmlnode
Hi, I have an XML document, created from ADO DataSet, which contains XML data in some nodes shown below: <NewDataSet> <Table> <field_name>My Selection</field_name> <field_type>dropdown</field_type> <field_choice_text> &lt;Choices&gt;&lt;Choice choice_text=\"xxx\" /&gt;&lt;Choice choice_text=\"yyy\" /&gt;&lt;Choice choice_text=\"zzz\" /&gt;&lt;/Choices&gt; </field_choice_text> <field_answer> xxx </field_answer> </Table> </NewDataSet> How can I get ...

Exchange 5.5 Fatal Bug
Hello, Apparently, no one at Microsoft has taken notice of the following posts on this newsgroup, all of which reference the same problem: http://communities.microsoft.com/NewsGroups/previewFrame.asp?ICP=3DGSS3&s= LCID=3DUS&sgroupURL=3Dmicrosoft.public.exchange.admin&sMessageID=3D%253C0= d0601c3a546%25247c1dd710%2524a301280a@phx.gbl%253E http://communities.microsoft.com/NewsGroups/previewFrame.asp?ICP=3DGSS3&s= LCID=3DUS&sgroupURL=3Dmicrosoft.public.exchange.admin&sMessageID=3D%253C0= 3f201c3a592%2524f09f0ef0%2524a601280a@phx.gbl%253E http://communities.microsoft.com/...

BUG: Outlook treats new message window as a dialog box
Applies to: Outlook 2000/2002/2003 (possibly also earlier versions, but not tested) Tested with: OL 2000 on Windows 98 SE OL 2003 on Windows XP Pro SP2 SYMPTOMS When Outlook is called externally to create a new message, it will treat the new message window as a dialog box. This has the consequence that the whole application is locked until one disposes of the "dialog box" either by sending the message or closing it. An alternative scenario is such that Outlook is not running, and the call is made to create a new message. In such case, if one attempts to start Outlook, one gets the...

CTreeCtrl and deleting items
Hi, I am having troubles with the CTreeCtrl class. Here is what I do (tested under VC 6, VC .Net 2002 and 2003) : 1. Wizard -> new dialog 2. Add a tree control & add variable for that control (m_ctrlTree) 3. Add a new button and implement the event corresponding to a click on that button with that code : m_ctrlTree.InsertItem( "An item" ); m_ctrlTree.DeleteAllItems(); m_ctrlTree.InsertItem( "Another item" ); With VC 6 everything is well, I see "Another item" in my tree control. However, with VS .Net 2002 and 2003 nothing ap...

Possible BUG Assoc VB, M$ latest security Update
Downloaded latest security Updates from M$ last night. (4/16/2009) Had 9 updates installed my system. After reboot attempted to access a VB project. Project OK, but VB IDE acting odd. 1) Any old project the IDE Property page is -- blank -- and just shows the two tabs at the top. 2) Any new project IDE appears to work fine. Anyone else have this issue?? Forgot System Info: XP-Pro(SP3) and VB5(SP3) "David" <NoWhere@earthlink.net> wrote in message news:uj$PEki3KHA.3728@TK2MSFTNGP06.phx.gbl... > Downloaded latest security Updates from M$ l...

What is the difference between XmlNode and XmlElement?
What is the difference between XmlNode and XmlElement? I'm trying to implement the code at http://www.devx.com/dotnet/Article/11616/0/page/3 in C# and I'm getting an error at this line: this.appSettingsElement = this.xml.SelectSingleNode("//configuration/appSettings"); Error: Cannot implicitly convert type 'System.Xml.XmlNode' to 'System.Xml.XmlElement' Thanks. Pluto wrote: > What is the difference between XmlNode and XmlElement? The same as between fruit and apple. XmlElement is particular type of XmlNode. > this.appSettingsElement = > this....