XmlTextReader Question #2

Hi,
I am starting out an xml file, example's below. It will be like that but 
larger. I am having problems actually getting at the inner nodes. Example the 
items I named InputOne, State, DebounceOn. Not sure how to get each data item
Any help, directions would be appreciated.
Right now I am doing in C#,

SystemIO.StreamReader stream = new SystemIO.StreamReader("theFile.xml);
XmlTextReader reader = null;
reader = new XmlTextReader(stream);
while( reader.Read())
switch(reader.NodeType)
{
  case XmlNodeType.Element:

   Console.Write( reader.Name + reader.Value);
   break;

  case XmlNodeType.Text:
   
    Console.Write( reader.Value);

   break;

  case XmlNodeType.EndElement:
   Console.Write( reader.Name);

  break;

}//end switch
  


<?xml version="1.0" standalone="no" ?> 
- <!-- Data point info for the Input Module
  --> 
- <InputModule>
  <ModuleName>Front Panel Input Info</ModuleName> 
  <ModuleNumber>0x70</ModuleNumber> 
- <!-- Input module points status
  --> 
- <InputPoints>
- <InputOne>
  <State>Disable</State> 
  <DebounceOn>12</DebounceOn> 
  </InputOne>
- <InputTwo>
  <State>Battery</State> 
  <DebounceOn>10ms</DebounceOn> 
  </InputTwo>
- <InputThree>
  <State>Ground</State> 
  <DebounceOn>10ms</DebounceOn> 
  </InputThree>
- <InputFour>
  <State>Ground</State> 
  <DebounceOn>10ms</DebounceOn> 
  </InputFour>
- <InputFive>
  <State>Battery</State> 
  <DebounceOn>10ms</DebounceOn> 
  <DebounceOff>10ms</DebounceOff> 
  </InputFive>
  </InputPoints>
  </InputModule>

Thanks
Jeff
0
jc1 (91)
6/9/2006 2:05:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
713 Views

Similar Articles

[PageSpeed] 37


JC wrote:

> I am starting out an xml file, example's below. It will be like that but 
> larger. I am having problems actually getting at the inner nodes. Example the 
> items I named InputOne, State, DebounceOn. Not sure how to get each data item
> Any help, directions would be appreciated.

With XmlReader there are many ways to tackle this, here is one example 
that checks for certain element nodes and then uses ReadElementString to 
read out the child elements you are looking for:

     XmlTextReader xmlReader = new XmlTextReader(@"file.xml");
     while (xmlReader.Read()) {
       switch (xmlReader.NodeType) {
         case XmlNodeType.Element:
           switch (xmlReader.Name) {
             case "InputOne":
               goto case "InputFive";
             case "InputTwo":
               goto case "InputFive";
             case "InputThree":
               goto case"InputFive";
             case "InputFour":
               goto case "InputFive";
             case "InputFive":
               Console.WriteLine("{0}:", xmlReader.Name);
               xmlReader.Read();
               Console.WriteLine("State: {0}", 
xmlReader.ReadElementString("State"));
               Console.WriteLine("DebounceOn: {0}", 
xmlReader.ReadElementString("DebounceOn"));
               Console.WriteLine();
               break;
           }
           break;
       }
     }
     xmlReader.Close();

Result with your example input

InputOne:
State: Disable
DebounceOn: 12

InputTwo:
State: Battery
DebounceOn: 10ms

InputThree:
State: Ground
DebounceOn: 10ms

InputFour:
State: Ground
DebounceOn: 10ms

InputFive:
State: Battery
DebounceOn: 10ms


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
6/9/2006 2:43:50 PM
Hi Martin,
Thanks for the response. Looks pretty decent. I will try that out.
Thanks
Jeff

"Martin Honnen" wrote:

> 
> 
> JC wrote:
> 
> > I am starting out an xml file, example's below. It will be like that but 
> > larger. I am having problems actually getting at the inner nodes. Example the 
> > items I named InputOne, State, DebounceOn. Not sure how to get each data item
> > Any help, directions would be appreciated.
> 
> With XmlReader there are many ways to tackle this, here is one example 
> that checks for certain element nodes and then uses ReadElementString to 
> read out the child elements you are looking for:
> 
>      XmlTextReader xmlReader = new XmlTextReader(@"file.xml");
>      while (xmlReader.Read()) {
>        switch (xmlReader.NodeType) {
>          case XmlNodeType.Element:
>            switch (xmlReader.Name) {
>              case "InputOne":
>                goto case "InputFive";
>              case "InputTwo":
>                goto case "InputFive";
>              case "InputThree":
>                goto case"InputFive";
>              case "InputFour":
>                goto case "InputFive";
>              case "InputFive":
>                Console.WriteLine("{0}:", xmlReader.Name);
>                xmlReader.Read();
>                Console.WriteLine("State: {0}", 
> xmlReader.ReadElementString("State"));
>                Console.WriteLine("DebounceOn: {0}", 
> xmlReader.ReadElementString("DebounceOn"));
>                Console.WriteLine();
>                break;
>            }
>            break;
>        }
>      }
>      xmlReader.Close();
> 
> Result with your example input
> 
> InputOne:
> State: Disable
> DebounceOn: 12
> 
> InputTwo:
> State: Battery
> DebounceOn: 10ms
> 
> InputThree:
> State: Ground
> DebounceOn: 10ms
> 
> InputFour:
> State: Ground
> DebounceOn: 10ms
> 
> InputFive:
> State: Battery
> DebounceOn: 10ms
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
jc1 (91)
6/9/2006 2:57:01 PM
Reply:

Similar Artilces:

Time question
I need a formula that would figure out what time it would have to be to complete a 40 hour week The information I have to plug in is this. Current total hours - 37 hrs 32 mins Current time is - 12:39 pm What time does it have to be to complete 40 hours? Seems like it should be simple but.... -- gueyo A1: 37:32:00 B1: 40:00:00 C1: 12:39 PM D1: =C1+(B1-A1) -- "Actually, I *am* a rocket scientist." -- JB (www.MadRocketScientist.com) Your feedback is appreciated, click YES if this post helped you. "gueyo" wrote: > I need a formula that w...

How can I insert a cell reference in a footer (eg for variable foo #2
Any ideas on how to do this? I'm trying to create a template with the doc reference number in the footer However, I'm trying to avoid users having to edit the footer (because this just wont get done). Private Sub Workbook_BeforePrint(Cancel As Boolean) With ActiveSheet .PageSetup.LeftFooter = .Range("A1").Text End With End Sub This code should go in the ThisWorkbook code module. -- HTH RP (remove nothere from the email address if mailing direct) "wngg001" <wngg001@discussions.microsoft.com> wrote in message news:8A0F9D9E-269F-45CF-A6E3...

Test Mail...Please Ignore #2
Testing NNTP Client, Please ignore message Thanks ...

Drop down menu #2
Is is possible when you have a drop down menu, to have excel short list the menu as you type in more charcaters of the text. For example a have a list of several hundred customers. I start inputting the first few letters of the customers name, I would like that list of several hundred to be shortened to only include thaise customers that begin with the letters I have typed in. Thanks Think this previous post by Debra Dalgleish would be of help: "Although data validation doesn't support autocomplete, there's a sample file here that provides a combobox from which you can se...

Associated external Account #2
Dear all, Just got some of our exch2k users migrated to another org exch2k3. Found that associated external account rights which never seen before in 2k. Wish to know the purpose of this account and when is the best time to use it. Please help and thousand thanks. regards Granting Access to External Accounts http://www.microsoft.com/technet/prodtechnol/exchange/guides/WorkingE2k3Store/8c4befe3-3815-4b6b-a759-1e5a2878499d.mspx -- Bharat Suneja MCSE, MCT -------------------------------- "Elton Seng Yan Thung" <sengy01@pd.jaring.my> wrote in message news:enFBAvpwFHA...

virus scanning #2
I really get prompted for "requesting virus scan", and I don't know ho to disable it; the warning is located beside ready, in Excel bar -- Gerbati ----------------------------------------------------------------------- Gerbatin's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1523 View this thread: http://www.excelforum.com/showthread.php?threadid=27651 What antivirus software do you use? I think/hope the solution will involve a setting that you can toggle in that program. (maybe you missed an option???) The antivirus program doesn't have t...

2 questions about Exchange Server 2000
1. How, or where, do I find out where Service Pack level I have installed? I see that I downloaded SP3, but I can't tell if it was ever installed. 2. Clients have Outlook 2000. Inbox is open. Last message is selected. No new mail. Then, if you click on a different message, you get the "new mail has arrived..." message. It seems to only deliver new mail when you change messages. Any thoughts? 1. In Exchange System Manager, highlight the Servers container. It should show you all servers in the right pane along with their service pack level. 2. Sounds like something is b...

Turn data #2
Is there a way to turn the data in an Excel spreadsheet so that what is on the top is now on the side and what is on the side is now on top? I need to export my spreadsheet into Access but, I can't get it to format correctly in its current orientation. ~Make a backup copy of your data to work from (just in case, so you don't lose data) ~Highlight the entire range of data; click >Edit >Copy ~Choose a new location, on a different sheet perhaps; click >Edit >Paste Special and select the Transpose box; click OK Does that do it for you? thank you so much. You are a genius...

Only 1 taskbar button when i open 2 excel documents
Hi all. When i open 2 excel documents i have only 1 taskbar button on the taskbar even though i did not choose the option to group similar taskbar buttons under taskbar properties. Hence when i want to switch between the 2 documents i need to go to window and select them. Hence how do i solve this so that i can have 2 taskbar buttons of the excel documents on the taskbar? Thks in advance. Tools>Options>View, check Windows In taskbar -- HTH Bob Phillips "inenewbl" <inenewbl@discussions.microsoft.com> wrote in message news:6F715432-2EB2-47AC-B737-56D63F37537A@mi...

Pivot Table fields #2
Is there a way to format multiple pivot table fields at one time and have them refresh that way, rather than having to select each column and choose the format options? Thanks CLou: I think the solution for you is to open the Pivot Table Toolbar and select the Field Settings icon. This sets the format for all results for that particular field. One limitation that I haven't found a way around is getting a preferred column size to "stick" and not reset after a table refresh. Bruce >-----Original Message----- >Is there a way to format multiple pivot table fields at ...

Business Cards #2
I am trying to create business cards using Microsoft Publisher 2002 on XP. Where would I find the template for Avery 8397, or for any of the Avery business card products. In page setup, select business cards, click Change copies per sheet and adjust the margins to fit your template. Avery has blank templates for downloading, choose Cards, there will be a list to select from. Your number was not among them but generally business cards are pretty much alike. http://www.avery.com/us/Main?action=software.BlankTPLHierarchy&catalogcode=WEB01&node=0 -- Mary Sauer MS MVP http://office.mi...

Last Question regarding ITems
I am unclear as to how I should take care of this item... Take for example I order a carton or case of items by I only sell these items by the single item. So in a case there is 36 or 48 or 60 of one item. How Should I enter this into RMS? I want to be able to buy 1 cs and recieve the inventory and have RMS automatically make it so that I have 36, 48 or 60 of them available. parent = case child = individual like items within case search help file for "parent child" "Pr0ject" <Pr0ject@discussions.microsoft.com> wrote in message news:F9E706E8-75B1-4E64-ACCF-72EAE...

Can not create Matrix Item please Help RMS 2.0
RMS 2.0 Can not create Matrix Item please Help When trying to create any new items I receive error message This is the message (-2147217864) Row Cannot be located for updating. Some values may have been change since it was last read. Manger still creates standard items but still receives message with out this number in message -2147217864 ...

Macro Recorder #2
I have a very basic question( I think). When you are recording a Macro how do you stop and then restart where you left off? For example I have a repetitive task that moves columns from one spreadsheet to another. The problem is that there are about 40 columns I am required to move. As I record the macro can it be stopped and then restarted if I have to close Excel and return later? I can't find the answer to my question documented anywhere. Thank You, Greg You can stop it, but when you start again it will create a new subprocedure, you can go in and copy/paste the second after the firs...

Date Range #2
Hi, Can someone please assist me with the following issue: I am currently using the formula noted below to direct another application ( Bloomberg ) to select prices from the previous 6th business day. My question is> Is there any way to revise the formula to exclude US holidays for successive years (i.e. for 2005, 2006...) without having to manually change the date entries each year, in the formula? =WORKDAY(Today(),-6, {"5/31/04","7/5/04","9/6/04","11/25/04","12/25/04","1/1/05" }) Thank you I'd recommend listing...

2 mirror files with :1 and :2
Not sure how, but have 1 excel file, lets call it FILEA.xls and when I open it, it opens a FILEA:1 and a FILEA:2 workbook. Any change made to FILEA:1 gets repeated in FILEA:2 and vice versa. Looks like some sort of mirroring, or changes being tracked, but track changes is turned off. Any help is appreciated! Hi you've opened two windows of the same workbook (from the window /new window menu) - just close one and then save - this should solve the problem Cheers JulieD "DJR" <DJR@discussions.microsoft.com> wrote in message news:F0F6BDF5-9DC2-486E-947C-ABBB6C4544...

using a macro question revisited
Concerned that the thread was bypassed after going 4 deep, I have reposted it with full includes. The way the macro works as currently written, it can return to multiple cells; but in this instance, I just need it to return either the sum of 2 randomly generated numbers between 1 and 6 (simulating a dice roll), or a single randomly generated number between 1 and 6, and then have the cell be stable after that is done (not constantly recalculating with every chnage made to the spreadsheet). "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message news:uBokaQVAGHA.2...

Uninstalling Office 2003 Service Pack 2
I have installed the Service Pack 2 for Office 2003 and have decided that it causes too many problems with Outlook 2003. For example, it sees certain emails as "Junk Mail" and (evidently) believes them to be "phishing". Even after placing these emails in my Inbox and adding the sender to the white list, it refused to allow me to open links from any web page link within the email. I understand that I cannot simply uninstall Service Pack 2, that I must install Office 2003 and then reinstall, without, of course, reinstalling the Service Pack. But if I do that, I wonder...

Comparing Worksheets #2
I have 2 worksheets that should be identical. One I know has been changed. Is there any way to compare the 2 to track changes. Darryll One way is to use a third sheet. In A1 type =Sheet1A1=Sheet2A1 This will return TRUE or FALSE. Fill this across and down as many as you need Andy. "Darryll" <Darryll_lamb@hotmail.com> wrote in message news:2618f01c38e4c$0c390cf0$a601280a@phx.gbl... > I have 2 worksheets that should be identical. One I know > has been changed. Is there any way to compare the 2 to > track changes. Thanks for your help Andy. All seems ok. >-----...

Few Basic Questions
I am a brand user new to Microsoft RMS as well as C-store business so have some fairly basic questions (if I can get myself up to speed with FAQ etc, feel free to pass the pointer). About to lease (leading to purchase) a C-store where I am investor and will rely on my partner to operate it. Evaluating POS options to bring operational transparency and efficiency as store is run with manual register today. <> Best place to find documentation / config guides? I have self-installed 60-day demo version RMS on two test PCs which works fine but product documentation included is path...

Simple question
I have an xls sheet that always print 6 copies. When ever I want to print, I have to change it to 1 copy. It's only this one xls sheet. Everything else prints 1 copy like it's suppose to. It's not the printer settings. Like I said, it's just this one xls sheet. Can someone tell me how to make it print 1 copy only and then stay as 1 as the defualt. I have made many changes to the sheet and saved it many times, but it always defaults to 6 copies. Very Strange. Thanks in advance. Phil If maybe as simple as this, as each page can have the page count se individua...

Money 2004 crash on startup #2
just find that it only crash when i use my current user, not happening when i logon as another user, seems my profile has some problem, maybe more startup & program installed. any idea on how to troubleshoot ? =========== just install in my WinXP SP1, which has IE6.0 SP1 installed already. Money2004 Std keep crashing on startup after install. with error dialog of "restart Money - Send / don't send report" any idea ? a further findings, i run Money2004 using "run as" another user, it works ! using local adm or domain userwith local adm right also run correctly....

Change print driver from PS level 1 to level 2
When printing in Publisher 2003 only, on and HP business inkjet 1100 I'm told that I need to set the PostScript language level to level 2 or higher. Following the instructions, I can't make the changes as directed in corrections from the error message, nor can I find any other way to change it.. You receive a Publisher cannot print this publication error message when you print as CMYK composite in Publisher 2003 http://support.microsoft.com/default.aspx?scid=kb;en-us;819594 -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.co...

Sum Formula Question
I was having trouble with a specific formula. Assistance would be greatly appreciated. I have a form that contains a form header, detail, and form footer. The detail section contains fields that are doing calculations. There is a text box that has source info going into Hours on a table. The data on that field has a formula: =DSum("[Hours]","Labor Metrics","[Tech manual ID] =Forms![Labor Metrics (Project)]![Labor Metrics (Project) subform]![Tech Manual ID]") When the form is run, it brings up information for all the directed results. I am trying to get the...

outlook won't connect to server #2
I have just installed Outlook 2003. I haven't used Outlook before. I have a Hotmail plus account. I have set up outlook to use this Hotmail account, but I cannot connect to the server to do so. I am fully connected to the internet when I try, through my ADSL broadband connection. hoo22 <hoo22@discussions.microsoft.com> wrote: > I have just installed Outlook 2003. > I haven't used Outlook before. > I have a Hotmail plus account. > I have set up outlook to use this Hotmail account, but I cannot > connect to the server to do so. > I am fully connected to the...