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

Finding Children with XmlReader

The following is straight out of the msdn, except where I put in
if (reader.Name == "wx")

What I'm trying to do is print the word Inner along with the tag name and
value for any tag that's a decendent of the wx tag. Any suggestions?

Thanks,
--
Randy
using (XmlReader reader =
XmlReader.Create(@"c:\TestDocs\AutoComplaintSample .xml"))
{

while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
Console.WriteLine("<{0}/>", reader.Name);
else
{
Console.Write("<{0}", reader.Name);
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested
elements.
if (reader.Name == "wx") //Try to get all
child values for wx tag
{
//if it's a child value of wx, add the
word Inner to the writeline:
Console.Write("Inner: {0}",
reader.ReadInnerXml());
Console.WriteLine(reader.ReadString());
break;
}
else
Console.Write("\r\n<{0}>", reader.Name);
Console.WriteLine(reader.ReadString()); //Read
the text content of the element.
}
}
}
Aug 15 '06 #1
1 3633
Hi Randy,

Do you need to put Inner: tag before each descendent of "wx" element? If
so, you have to go through each sub-node of it and print them. Here is an
example:

using (XmlReader reader =
XmlReader.Create(@"c:\AutoComplaintSample.xml"))
{

while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
Console.WriteLine("<{0}/>", reader.Name);
else
{
Console.WriteLine("<{0}", reader.Name);
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested
elements.
{
if (reader.Name == "wx") //Try to get
all child values for wx tag
{
//if it's a child value of wx, add the
word Inner to the writeline:
Console.WriteLine("<{0}>", reader.Name);
XmlReader subreader =
reader.ReadSubtree();
subreader.Read();
while (subreader.Read())
{
switch (subreader.NodeType)
{
case XmlNodeType.Element:
Console.Write("Inner:
<{0}", reader.Name);
while
(subreader.MoveToNextAttribute())
{
Console.Write("
{0}='{1}'", reader.Name, reader.Value);
}
Console.Write(">");
break;
case XmlNodeType.Text:

Console.Write(subreader.Value);
break;
case XmlNodeType.EndElement:
Console.Write("</{0}>\n",
subreader.Name);
break;
}
}

//Console.WriteLine(reader.ReadString());
//break;
}
else
Console.Write("\r\n</{0}>",
reader.Name);
}
Console.WriteLine(reader.ReadString()); //Read
the text content of the element.
}
}
}
}

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Aug 15 '06 #2

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

Similar topics

5
by: xmlguy | last post by:
I believe this should be pretty elementary, but for some reason I cannot seem to think of how to write the an XML file from an incoming XML file. Basically this is what I do: Input: ...
2
by: xmlguy | last post by:
Cant seem to solve this problem I need to be able to re-use XmlReader and XPathDocument for an XSLT Transform. Basically I have defined following interfaces: Class Render (Common and...
11
by: Ben | last post by:
Hi, I'm just moving to VB.NET and I'm trying to load a recordset intoan XMLReader and loop through the records. When I use the.ReadElementString() method to get the next 'record' if it hasreached...
0
by: Matthew Heironimus | last post by:
According to the XML 1.0 (Third Edition) W3C Recommendation (http://www.w3.org/TR/2004/REC-xml-20040204/#sec-line-ends) all #xD, #xA, and #xD#xA character combinations should be converted to a...
1
by: Matthew Heironimus | last post by:
According to the XML 1.0 (Third Edition) W3C Recommendation (http://www.w3.org/TR/2004/REC-xml-20040204/#sec-line-ends) all #xD, #xA, and #xD#xA character combinations should be converted to a single...
1
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code:...
0
by: Jen | last post by:
My main question: "How can I get a TextReader or Stream object from an existing XmlReader?". Read on for more: I have an existing XmlReader. Let's call it reader1. I'm creating another reader,...
6
by: Rob Meade | last post by:
Hi all, I'm having a few difficulties with the above, ie I cant find any good examples anywhere of how to do what I want to do! I have an xml file on my desktop which I want to read in. ...
5
by: heday60 | last post by:
I've got this application that watches a directory for XML's and then parses them into a DB. It then moves them based on if the XML was succesful or a bad XML... foreach(FileInfo file in...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.