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

Parse tree-shaped xml with XmlReader

The xml's structure is like the following
<Directory>
<Directory>
<Directory>
<Directory>
</Directory>
</Directory>
<Directory>
<Directory/>
</Directory>
<Directory>
</Directory>
</Directory>
<Directory>
</Directory>
Yes, a very simple structure. Directory can contain other Directories
be empty. I would like to parse this xml. Say a class like this;
class Directory
{
public Directory SubDirectory;
public void AddSubDirectory(Directory);
}
But I'm confused with XmlReader. Could you please give me any simple
code snippet or psudo code for this task? Or any tutorial web page for
similar tasks.Thank you.

Nov 4 '05 #1
2 1435
I made some typoes. So I correct my post.
================================================== ====
The xml's structure is like the following
<Directory>
<Directory>
<Directory>
<Directory/>
</Directory>
</Directory>
<Directory>
<Directory/>
</Directory>
<Directory>
</Directory>
</Directory>
<Directory>
</Directory>
Yes, a very simple structure. Directory can contain other Directories
or can
be empty. I would like to parse this xml into a class. Say a class like
this;
class Directory
{
Directory[] SubDirectories;
public void AddSubDirectory(Directory);
}

But I'm confused with XmlReader. Could you please give me any simple
code snippet or psudo code for this task? Or any tutorial web page for
similar tasks.Thank you.

Nov 4 '05 #2
Here's some code I was just working on:

string xmlTarget = getPath() + @"\focus.xml";
XmlTextReader reader = new XmlTextReader (xmlTarget);
reader.MoveToFirstAttribute();
reader.MoveToContent();

while (reader.Read())
{

if (reader.Name.Equals("name")
&& reader.NodeType == XmlNodeType.Element)
{
sight += reader.GetAttribute("restart")+"|"; //retina 0
sight += reader.GetAttribute("subject")+"|"; //retina 1
sight += reader.GetAttribute("appserver")+"|"; //retina 2
sight += reader.ReadElementString("name") + "|"; //retina 3
//Debug.WriteLine(sight);
}
}

Sin Jeong-hun wrote:
I made some typoes. So I correct my post.
================================================== ====
The xml's structure is like the following
<Directory>
<Directory>
<Directory>
<Directory/>
</Directory>
</Directory>
<Directory>
<Directory/>
</Directory>
<Directory>
</Directory>
</Directory>
<Directory>
</Directory>
Yes, a very simple structure. Directory can contain other Directories
or can
be empty. I would like to parse this xml into a class. Say a class like
this;
class Directory
{
Directory[] SubDirectories;
public void AddSubDirectory(Directory);
}

But I'm confused with XmlReader. Could you please give me any simple
code snippet or psudo code for this task? Or any tutorial web page for
similar tasks.Thank you.

Nov 4 '05 #3

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

Similar topics

0
by: Chad Whitacre | last post by:
Hey all, I've been playing around with the parser module, and based on the documentation I would expect all symbols in a parse tree to be part of the grammar. For example, I find this line in...
1
by: Neil Zanella | last post by:
Hello, When I save the following file with the .xhtml or .xml extension I get the XML parse tree and the following message instead of the actual document. This XML file does not appear to...
10
by: dreamcatcher | last post by:
I want my program to parse INI files, only have little clue of how to do that, though, hope you guys might shed some light on this, thanx. for example:
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
0
by: asahin | last post by:
hi all; i need ability to change a page's looking at run-time by changing aspx page or construct control tree via reading a previously defined template. is there any way to parse an aspx...
4
by: TwinT | last post by:
Hi. I've got a small problem with parse trees... first off, I don't exactly know what it is. I'm a newbie, in a way, but I've been bravely trying to learn my way through all the confusion out in...
2
by: marc.wyburn | last post by:
I'm playing with XML and elementtree and am missing something but I'm not sure what...? I've create an XML file with Elementtree with a root of backup.xml. Attached to the root is a dirob and the...
3
by: Bint | last post by:
Hi, I'm trying to parse an xml file into an array tree. From the PHP site in the comments, I got this code. But it doesn't work for me. It's saying that the passed variable is not an array or...
0
by: snc85 | last post by:
Hi! can anyone help me to parse some string into tree... I have Q function, this is something like "if else" for example: Q<VSecCode=0?B0+B2:B1>
1
by: uche | last post by:
Hi Guys, I am trying to build a Parse Tree with the following grammar. I have implemented my insertions using a standard binary tree inserting algorithm. With the psuedocode below, can you guys...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
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,...
0
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...
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
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...

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.