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

XML Parsing

I have built an XML file like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <Drives>
  3.  
  4.  <Server id="Server01">
  5.   <Share>
  6.     <Letter>A</Letter>
  7.     <Folder>Share1</Folder>
  8.   </Share>
  9.   <Share>
  10.     <Letter>B</Letter>
  11.     <Folder>Share2</Folder>
  12.   </Share>
  13.   <Share>
  14.     <Letter>C</Letter>
  15.     <Folder>Share3</Folder>
  16.   </Share>
  17.  </Server>
  18.  
  19.  <Server id="Server02">
  20.   <Share>
  21.     <Letter>D</Letter>
  22.     <Folder>Share1</Folder>
  23.   </Share>
  24.   <Share>
  25.     <Letter>E</Letter>
  26.     <Folder>Share10</Folder>
  27.   </Share>
  28.  </Server>
  29.  
  30.  <Server id="Server03">
  31.   <Share>
  32.     <Letter>F</Letter>
  33.     <Folder>Share11</Folder>
  34.   </Share>
  35.  </Server>
  36.  
  37.  </Drives>
  38.  
And got some code:
Expand|Select|Wrap|Line Numbers
  1. (...)
  2.             XmlDocument xd = new XmlDocument();
  3.             xd.Load(OfficeXMLPath);
  4.             XmlNodeList nodelist = xd.SelectNodes("/Drives/Server"); // get all <Server> nodes
  5.  
  6.             //UNCPahtTextBox1.Text = OfficeXMLPath;
  7.             foreach (XmlNode node in nodelist) // for each <Server> node
  8.             {
  9.                 string ServerID = node.Attributes.GetNamedItem("id").Value;
  10.  
  11.                 { 
  12.                     XmlNode n = node.SelectSingleNode("Share");      // get the one <Share> node
  13.                     string Letter = n.ChildNodes.Item(0).InnerText;
  14.                     string Folder = n.ChildNodes.Item(1).InnerText;
  15.  
  16.                     comboBox2.Items.Add(Letter);
  17.                 }
  18.             } // foreach <Server> node
  19. (,,,)
  20.  
Now, The code above only adds to combobox First <letter> of each <share>, and does not get any second... or third <share> values in <Server> node. I am aware that SelectSingleNode Selects only one, but I can't figure out at this moment what/how I should proceed with it. Any ideas?
I have created the same in Powershell and I am trying to translate this one into c#, but looks like there is something I am missing.

Thank you
Feb 10 '10 #1
2 1646
K, nevermind :) I got it.... :D
Feb 10 '10 #2
something like this I had to come up with
Expand|Select|Wrap|Line Numbers
  1.                 XmlNodeList lstShare = node.ChildNodes;
  2.                 foreach (XmlNode nodeShare in lstShare) {}
  3.  
  4.  
Feb 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.