Counting children

 Hi,

I'm struggling to find a way to count all children per level in an xml source.

Source:
<SWITCH-RDM port="BSC:BEERM-RBL2:107">
    <S1464 port="BSC:BEERM-RBL2:107" />
    <S1465 port="RXI:RX1RM-ETMC41:MS1-14-30" />
    <S1469 port="BSC:BEERM-RBL2:251" />
    <S6651 port="RXI:RX4RM-ETMC41:MS1-8-05">
        <S0287 port="RXI:RX4RM-ETMC41:MS1-8-05">
            <S0542 port="RXI:RX4RM-ETMC41:MS1-8-05">
                <S1473 port="RXI:RX4RM-ETMC41:MS1-8-05" />
            </S0542>
        </S0287>
    </S6651>
    <S6651 port="RXI:RX4RM-ETMC41:MS1-8-06">
        <S0287 port="RXI:RX4RM-ETMC41:MS1-8-06">
            <S0542 port="RXI:RX4RM-ETMC41:MS1-8-06" />
        </S0287>
    </S6651>
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-43">
        <S1479 port="RXI:RX2RM-ETMC41:MS1-12-43" />
    </S0376>
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-44" />
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-45" />
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-46" />
    <S0037 port="RXI:RX3RM-ETMC41:MS1-18-01">
        <S2358 port="RXI:RX3RM-ETMC41:MS1-18-01">
            <S1532 port="RXI:RX3RM-ETMC41:MS1-18-01" />
        </S2358>
    </S0037>
</SWITCH-RDM>

So what I'm trying to do is: 
- count how many childnodes are in SWITCH-RDM,but only the ones directly in 
it, not the childnodes' childnodes.
- Count how many childnodes there are in each childnode

If I do SelectNodes("Switch-RDM").count I get the result of 1.
If I do SelectNodes("*").count I get all the nodes.

please help with this.

rg,
Eric

0
Eric1 (389)
10/18/2009 4:56:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
1861 Views

Similar Articles

[PageSpeed] 34

Eric wrote:
>  Hi,
> 
> I'm struggling to find a way to count all children per level in an xml source.
> 
> Source:
> <SWITCH-RDM port="BSC:BEERM-RBL2:107">
>     <S1464 port="BSC:BEERM-RBL2:107" />
>     <S1465 port="RXI:RX1RM-ETMC41:MS1-14-30" />
>     <S1469 port="BSC:BEERM-RBL2:251" />
>     <S6651 port="RXI:RX4RM-ETMC41:MS1-8-05">
>         <S0287 port="RXI:RX4RM-ETMC41:MS1-8-05">
>             <S0542 port="RXI:RX4RM-ETMC41:MS1-8-05">
>                 <S1473 port="RXI:RX4RM-ETMC41:MS1-8-05" />
>             </S0542>
>         </S0287>
>     </S6651>
>     <S6651 port="RXI:RX4RM-ETMC41:MS1-8-06">
>         <S0287 port="RXI:RX4RM-ETMC41:MS1-8-06">
>             <S0542 port="RXI:RX4RM-ETMC41:MS1-8-06" />
>         </S0287>
>     </S6651>
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-43">
>         <S1479 port="RXI:RX2RM-ETMC41:MS1-12-43" />
>     </S0376>
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-44" />
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-45" />
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-46" />
>     <S0037 port="RXI:RX3RM-ETMC41:MS1-18-01">
>         <S2358 port="RXI:RX3RM-ETMC41:MS1-18-01">
>             <S1532 port="RXI:RX3RM-ETMC41:MS1-18-01" />
>         </S2358>
>     </S0037>
> </SWITCH-RDM>
> 
> So what I'm trying to do is: 
> - count how many childnodes are in SWITCH-RDM,but only the ones directly in 
> it, not the childnodes' childnodes.
> - Count how many childnodes there are in each childnode
> 
> If I do SelectNodes("Switch-RDM").count I get the result of 1.
> If I do SelectNodes("*").count I get all the nodes.

If you are interested in the _element child nodes_ of the root element 
then use e.g.
XmlDocument doc = new XmlDocument();
doc.Load("file.xml");

and then

int count = doc.SelectNodes("SWITCH-RDM/*").Count;

or

int count = doc.DocumentElement.SelectNodes("*").Count;

There is also a ChildNodes collection but that will contain all kind of 
nodes (i.e. element nodes but comment and processing instruction nodes 
as well and even text nodes with white space if PreserveWhitespace on 
the document has been set).

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1777)
10/18/2009 5:28:13 PM
Reply:

Similar Artilces:

counting number of word in a cell
is there a function can count number of word in a cell example: A B username count kok, hong, Lee chan, NG Ti, Lee after counting A B username count kok, hong, Lee 3 chan, NG 2 Ti, Lee 2 You can count the number of spaces in the cell then add 1: =LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1 -- Biff Microsoft Excel MVP "kokhong" <kokhong@discussions.microsoft.com> wrote in message news:F7A04812-9F1E-430D-9...

Counting 11-20-07
I have a DB with 5000 records. There is a field called 1st Choice that I want to count. There are 30 different choices for for "1st Choice". I need to count the total number for each of the 30 choices and display those totals in a report that I am creating. I am new to Access. In the control source field in the report I tried: =DCount("[1st Choice]","[Resident Registration]") all this does is total all the records and repeat that number throughout the report. Does anybody have any ideas on the best way to accomplish this? A friend has suggested a query ......

Count between a Date Range
I have a number of columns that has dates in them and blank cells, and would like to count the number of instances a date�s falls in betwee current date and earlier. I have not been successful using the eithe the Countif ,Sumif, or Sumproduct formula. Can someone please assist me, because I have been racking my brain ove this for 3 days now -- Miguelr ----------------------------------------------------------------------- Miguelre's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1462 View this thread: http://www.excelforum.com/showthread.php?threadid=26299 H...

serial communication data counting
hi, using vc++ 6.0 ,i developed serial communication.it contains three edit box,one list box,i kept one edit box as sending data in same side i kept send button also.also one edit box in sending side to count a character.i kept list box as receive mode.also one more edit box in receive side to count a character in receive side. so now i want to count number of characters in both the sides of edit box .can any one plz give me steps to develop this, with source code if there. thanks & regards anand You may want to take a look at this class: http://www.naughter.com/serialport.html T...

Sum & Count on Form.
i had a form on which i had created a combo box that contain several employees. I want the amount earned (Currency Format) by each employee to be displayed on the formin the text box. Other fields in my table are; Empid,Empname,amount earned.etccc please tell me how to solve this. I mean i want the sum to be displayed in the text box whenever i select an employee from the combo box. On Tue, 18 May 2010 20:56:01 -0700, Chiki <Chiki@discussions.microsoft.com> wrote: >i had a form on which i had created a combo box that contain several employees. > >I want...

Code for counting number of records in query
Hi, I need to count the number of records in queries quite a lot to check for duplicates or to ensure the data I'm about to append hasn't already been added & then inform the user. I've been using this code to get the count of records: Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSQLcnt As String strSQLcnt = "SELECT Count(…………. etc Set db = CurrentDb() Set rs = db.OpenRecordset(strSQLcnt) xx = rs.Fields(0) rs.Close: Set rs = Nothing Set db = Nothing If xx = 0 Then etc Is there a simpler or shorter way...

Is it possible to count the day of Month/Year?
Is it possible to count the day of Month/Year? Hi Joe I'm not sure that I understand your question, but if you are asking whether you can determine the number of days in each month of the year then try the following. In cell A1 enter the Year you require e.g. 2006 In cells A2:A13 enter the numbers 1 to 12 In B2 =DAY(DATE($A$1,A2+1,0)) and copy down through cells B3:B13 Alternatively, if you wanted to show Month names in cells A2:A13, enter in A2 =DATE($A$1,row()-1,1) Format>Cells>Number>Custom mmm to show Jan Copy down through cells A3:A13 Change formula in B2 to =DAY(DATE...

2 Column Counts & Display
I have in field "Nature" set two columns to be looked into and presented in a combo box, Column 1 showing the Account ID and Column 2 the Account Title. However, when I select an entry only the first column, i.e. Account ID is displayed. I want the entry to be either showing both or the second column's relevant entry i.e. either: Account ID | Account Title or Account Title Any suggestions/guidance? -- Thanx in advance, Best Regards, Faraz Hi Faraz , A combo box that is not in dropped down mode will only display the first visible column. The easiest way ...

countif Access 2000
I,m trying to count how many numbers, in a column, that have a value greater than zero. Any ideas anyone In query design view, type something like this into a fresh column in the Field row: [MyField] > 0 Depress the Total button on the toolbar. Choose Count under this field. If you wanted to do it in code: DCount("*", "MyTable", "MyField > 0") -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Zab" <Zab@discu...

Count Formula
Hi everybody, I need your help in formula that counts a group of the same data as one while having different info in the next column: It is important that it should count based on column B or C but not A amd if no info in front of a name then it should not count. The results of each column must be col B = 3, col C = 4. Please help. Thanks. col A col B col C Jack 10 20 Jack 20 10 Jack 45 15 Mary 15 Mary 16 Mary 9 Sam 80 15 Sam 45 12 Sam 15 9 Sam 10 9 Max 10 Max 11 Max ...

Counting Repeated text or duplicates in a list
I need a simple formula to count the total number of repeated text in a list (column). Say there is thousands of entries (confirmation numbers) both numeric, alphabetic and alpha-numeric but many of the entries are repeats. How can I calculate in one cell the total number of repeated instances in the list? And I can't sort the list, just calculate the number of repeated instances in the list just the way it is, and the list is still growing, so I need the formula to be able to count all instances in the list even as they are being added. plz help ! =COUNTA(A1:A50)-SUMPRODUCT((...

COUNT Fields from Subform in Main Form
I am trying to count the number of parcels in a field called [ParcelQty] in my main form [Field Packs] from a field called [SBLPID] in my subform [Query.QrySBLFP] (Note: the table name is SBL FP). The Master and Child fields are FPackID. I used an example from the Help index and came up with this formula: =ParcelQty: (SELECT COUNT([SBLFPID]) FROM [SBL FP] WHERE [SBL FP].[FPackID] = [Field Packs].[FPackID]) It does not work in the form (I tried with and without the begining equal sign), so I tried leaving the form field unbound and using the ParcelQty field in QryFieldPacks. I get t...

Count occurrences of filename in column
I want to use VBA to count the occurrences of a filename in column M, such as "myfile.xls". Problem is, each time the name appears (after the first one), it'll include a number, like "myfile(2).xls", "myfile (3).xls", and so on. Also, I can't just count occurrences of the name because it could appear as a non-filename ("myfile"), without the .xls extension, and I don't want to count that. When I have finished counting them, I want to add another instance, with a higher number than the existing ones, also in column M. I've been ...

Count keystrokes
I have a simple data entry form where users are requested to type in a description of work performed. I want to limit the amount of text they can enter and would like to display a "live" counter that tells them how many characters they can enter. This counter would decrease as they made each keystroke and stop at zero. Appreciate any suggestions or alternatives to the counter. Here's an example: http://cjoint.com/?fCrDQAoHPX Userform's code is as follows. Cheers, -- AP '--------------------------------------------------------------- Public bCancel As Boolea...

Stock Count of Parent and Child items
Hi there, Just wondering how anyone else reconciles the parent and child items in a stock take? this seems to be a very difficult process unless I am getting it wrong. Ivan ...

Creating queries asking for counts
I have a database for our hospital diabetes center. We created a great set of forms etc... to stream line our paperwork, now we need to create some reports. I am trying to create queries to show: Number of patients who have Type 1 diabetes, Number of patients who have Type 2 diabetes, number of patients who have gestational diabetes 1-18 years old and >19 years old. I can create a query for each one of these number of patients and get a long list of each. As soon as I insert a count or other criteria into the query Access comes back and tells me the expression is to complicat...

formula to count formatted result value
In column A enter the date and in B a formula copies A1 reformated as day (dddd). How can I count the results of colums "B" (number of times each day appears)? Col A Col B 1/1/10 9:13 PM Friday 1/3/10 3:25 PM Sunday =SUMPRODUCT(--(WEEKDAY(B$1:B$100)=ROW(A1)),--(B$1:B$100<>"")) and copy down through rows 1 to 7, will show the count for each day from Sunday to Saturday. -- David Biddulph "WD" <WD@discussions.microsoft.com> wrote in message news:61D6B8CB-C358-4B1E-AB39-36F190CFD27E@microsoft.com... > In c...

Total filtered record count on filtered adp form
Hello everyone, I have a form in an ADP front end to SQL server 2005. I know how to get a total record count for the record set but when I filter the form the count stays the same. I would like to show the same number that shows on the box between the navigational butons. "Jess" <Jess@discussions.microsoft.com> wrote in message news:80F2027E-8A86-469C-8BE6-8E6AAE4DE073@microsoft.com... > Hello everyone, > > I have a form in an ADP front end to SQL server 2005. I know how to get a > total record count for the record set but when I filter the form t...

Counting unique values with variables
I have a similar question, except, I need to count unique instances where there is another variable. Sample Data: Program Student University 1 John North University 1 Steven North University 1 James South University 2 Susie Case University 2 Laura West University 2 Lisa North University So, in this sample data, I would need to count the number of unique universities per program, that is, Program 1 - 2 univeristies, program 2 - 3 universities. Additionally, ...

Count days inside 2 dates
Sorry, I have been trying all sorts of different formulas to get this right. I need a formulae that can calculate the numbers of day in C A guest arrives on A, left on B, total numbers of days on C. A B C 10/12/2008 11/12/2008 1 (days) 31/12/2008 03/01/2009 3 Much appreciated! Assume startdates in A2 down, enddates in B2 down Then in C2: =B2-A2 Format C2 as general (via Format>Cells), then copy down -- Max Singapore http://savefile.com/projects/236895 Downloads:19,000 Files:362 ...

Count last nonzero number in a column
Hi I have columns of numbers, A:Z. Each column has either numbers, zero's, or text. I need to find the row number that has the "Last" nonzero number. So if A1="car" , A2=0, A3=6, A4="Boat" I would need a value of 3, the last occurence of a nonzero number (6). Thanks for your help Hi try the following formula: =LOOKUP(2,1/((A1:A100<>0)*(ISNUMBER(A1:A100))),ROW(A1:A100)) -- Regards Frank Kabel Frankfurt, Germany "Jeff" <Jeff@discussions.microsoft.com> schrieb im Newsbeitrag news:FEA7DC58-6459-4F55-9DE4-984740EFC610@microsoft.com.....

how to count one value or another across multiple columns?
I have thre columns: One holds names (record keys), another could hold "X", the last can have a "Y". I want to know how many records have either an "X" or a "Y" value? For example: Column A Column B Column C Matt X Bill Y John X Y Fred X Y Tom How many records (i.e. column A) have either an X or Y? Hi! What result do you exp...

INVENTORY CYCLE COUNT IN EXCEL
This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C76BA5.E704DD20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello to all! I want to start an inventory cycle count program in my company. How can = Excel be used to do random selection? The only data I currently have is = a listing with the following headings: 1) Part Code 2) Part Description 3) Location Code 4) Quantity on hand 5) Unit Cost 6) Total Cost 7) Cateogry The accounting software does not provide, currently, a usage report that = I use to apply ABC ...

counting cells
I have a spreedsheet showing dates. My question is what formula can i used to count dates only in a column and not text such as " N/A" or " NR"? Hi, count will ignore text =count(A1:A4) "rbwn54" wrote: > I have a spreedsheet showing dates. My question is what formula can i used to > count dates only in a column and not text such as " N/A" or " NR"? > Use the Count function. It will ignore text. Regards, Fred "rbwn54" <rbwn54@discussions.microsoft.com> wrote in message news:9405CD28-9C6A-47...

How to count existing records where StudentID = ThisStudent
I'm trying to count the number of classes a student has in their "Student Schedule" table as we enter more records for that student. Assuming the records are entered in the order of the student's preference, then we can set the "Preference" field to be equal to the number of records. But I'm new to Access and it doesn't behave as I expect. I get runtime error '2001', "You cancelled the previous operation". Perhaps I need some kind of post or 'save record' command? I've attached the following code to the event called A...