473,586 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlReader-to-XmlReader skips nodes?!

Hi,

I have the following code to copy nodes from an XML document (XmlReader
reader) to some output (XmlWriter writer).

while (reader.Read ())
if (reader.MoveToC ontent () == XmlNodeType.Ele ment)
break; // forward the reader to the document element

writer.WriteSta rtDocument (false);
writer.WriteSta rtElement ("XmlStore") ; // write the document element
itself

while (reader.Read ())
if (reader.NodeTyp e == XmlNodeType.Ele ment)
writer.WriteNod e (reader, true); // copy nodes

// might want to insert more nodes here

writer.WriteEnd Element (); // close document element

Now, if I use this to process the following XML:

<root>
<one><item1/></one>
<two><item2/></two>
</root>

what the XmlWriter produces is:

<XmlStore>
<one><item1 /></one>
<item2 />
</XmlStore>

Whatever happened to the <two> element? Only its child element <item2/> is
included in the output.

(Note, formatting to the XML bits added manually for clarity. The original
contains no whitespace and the writer uses no formatting. Still, all
combinations of source formatting, reader whitespace handling, and writer
output formatting produce the same result: the <two> node is missing in the
output.)
Nov 12 '05 #1
1 1792
But if I use
while (! (reader.EOF))
if (reader.NodeTyp e == XmlNodeType.Ele ment)
writer.WriteNod e (reader, true); // copy nodes
it works, so my issue is resolved. :)
Thanks anyway.
"Philipp Schumann" <ph**@mokka.org > schrieb im Newsbeitrag
news:uh******** ******@TK2MSFTN GP10.phx.gbl... Hi,

I have the following code to copy nodes from an XML document (XmlReader
reader) to some output (XmlWriter writer).

while (reader.Read ())
if (reader.MoveToC ontent () == XmlNodeType.Ele ment)
break; // forward the reader to the document element

writer.WriteSta rtDocument (false);
writer.WriteSta rtElement ("XmlStore") ; // write the document element
itself

while (reader.Read ())
if (reader.NodeTyp e == XmlNodeType.Ele ment)
writer.WriteNod e (reader, true); // copy nodes

// might want to insert more nodes here

writer.WriteEnd Element (); // close document element

Now, if I use this to process the following XML:

<root>
<one><item1/></one>
<two><item2/></two>
</root>

what the XmlWriter produces is:

<XmlStore>
<one><item1 /></one>
<item2 />
</XmlStore>

Whatever happened to the <two> element? Only its child element <item2/> is
included in the output.

(Note, formatting to the XML bits added manually for clarity. The original
contains no whitespace and the writer uses no formatting. Still, all
combinations of source formatting, reader whitespace handling, and writer
output formatting produce the same result: the <two> node is missing in
the output.)

Nov 12 '05 #2

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

Similar topics

0
987
by: pwinward | last post by:
Using C++ .NET 2003 and getting: "The breakpoint will not currently be hit. No executable code is associated with this line." My app links to my static library and when I try debugging either one, I can't debug any code from the library it calls, although I can debug the main app. It skips over the breakpoint even if I try setting it...
5
9200
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef RelatedID="118"/> <PersonName> <NameTitle Value="Mr"/> <FirstName>Clint</FirstName> <OtherName/> <AlsoKnownAs>Mr C Eastwood</AlsoKnownAs>
2
10681
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,...
3
1830
by: LC | last post by:
Hello all, Ive been using the treeview and for testing purpose i have created 2 Parent Nodes and 5 child nodes within each parent node i.e.- CN = Child Node Parent Node - CN - CN - CN
3
12131
by: juvi | last post by:
Hi, I have got a problem with Treeview.Nodes.Clear() under VB2005. When I have some nodes in my treeview and a force to clear() all nodes then it seems to work, because the nodes are not visible. But when I add new nodes and I want to look for a specific item then I only get the Items from the beginning --> something is not working with the...
1
2319
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the parent node has 100 nodes, I want to delete nodes 10 through 75, and not nodes 5, 10, 25 etc. I have a reference to the first and the last node in...
6
2133
by: VK | last post by:
I must be missing something very obvious, but my nightly head doesn't work anymore. Press "Insert" button to add <insnodes after each <br>. Now press "Delete" - only even <insare being removed. ins.length is reported properly, each <inshas "insert" class name. What a...? <html content="text/html; charset=iso-8859-1"
3
1215
by: vegtard | last post by:
by now, you have no doupt replied to many of mine and my buddy (børntard)'s questions about our faulty programming concerning the over-complicated mega-script to design your dungeons and dragons roleplaying character. well, i think i have cracked it. but theres one slight problem i cant seem to get my head wrapped around. i have an...
10
34451
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in TreeView1.Nodes) NodeCounter++; // other way int total = TreeView1.Nodes.Count;
0
7836
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...
0
8199
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, 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. ...
1
7950
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...
0
5389
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...
0
3835
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...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
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...

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.