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
1827 Views

Similar Articles

[PageSpeed] 2

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:

If statement to export query if record count is not null
Greetings, thank you very much to all who are reading this. Basically I have an automated email that goes out every Monday. Very simply it uses sendobject to email a query. I would like to add some logic that basically looks at the record count and if it isn't null...sends teh email as is...if the record count is empty I would like to have it send an email that basically says "The record set this week is empty." Below is the module converted from the original macro. I was having trouble modifying the module so any help would be greatly appreciated. Thanks in ...

Different Names Count
Hi guys Hope someone can help Here is an example of what I am trying to do Cell range A1 - A12 Bob James Jill George Tracy Mike Bob Philip Graham Jack James Bob Different names = 9 Ignore repeated names, except once What formula would I need to put in cell A13 to give me this figure? Thank you in advanced Ravi Sandhu One way: A13: =SUMPRODUCT((A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")) In article <t0BXc.469$ZC5.190@newsfe2-win.ntli.net>, "Ravi Sandhu" <ravisandhu@mail.com> wrote: > Hi guys > > Hope someone can help ...

Counting Emails
Is there a way to have Outlook 2002 count emails by hour as they come in? We receive several hundred emails/day and they are auto-forwarded to different folders depending on subject. I would like to be able to know how many emails arrive per hour in each folder but have been unable to figure out if it's possible. Not possible as far as I know... Dale "Amy" <anonymous@discussions.microsoft.com> wrote in message news:07db01c3a93d$85a0e840$a001280a@phx.gbl... > Is there a way to have Outlook 2002 count emails by hour > as they come in? We receive several hundred ...

need to compare dates and count the results
I have two columns of dates. The first column is the date the event actually occurred or is 0 if nothing has been done yet. The second column is the target date by which the event should happen, the deadline. I was able to create conditional formatting for the first column. It turns each date green if the task was complete or if the due date was more than 24 hours from today. The date turns yellow if it is incomplete and the due date is 24 hours from today. The date turns red if it's incomplete, and it's target date is today or has passed. I would now like to be able to add up h...

Counting spefic cell (not a range) with a value greater than 1
I am looking for a formula to count specific cells and a range (A5, A10, A15, A20 and so on) but only count when the value is greater than $1.00. So if the value of cell A5 was $1.50, the value of cell A10 was $1.25, the value of cell A15 was $0.50 and the value of cell A20 was $2.00 the total count would be 3. I'm stumped! =SUMPRODUCT(--(LARGE((A5,A10,A15,A20,A25),ROW(INDIRECT("1:"&COUNT(A5,A10,A15,A20,A25))))>1)) however if you want to sum every 5th cell greater than 1 you can use =SUMPRODUCT(--(MOD(ROW(A5:A50),5)=0),--(A5:A50>1)) -- Regards, Peo Sjoblo...

Distinct Counts with Multiple Criteria
Each month we produce a complex report in Excel using thousands of rows of data. We've just been asked to add in a new table which needs to use distinct counts based on multiple criteria. I've included an example of the data below. How can I create a formula to complete the results table as I have manually entered below? A B C D 1 NAME DEPT LOCATION TYPE 2 Mary Finance A Primary 3 Sally Finance B Primary 4 Sally Finance B Primary 5 Mary IT A Primary 6 John Finance B Secondary 7 John Finance B Secondary 8 David Admin A Primary 9 John IT B Secondary 10 Da...

Count over group
I have a view that I want to count the occurrance of a FedIDNo only once in a group of linked SSNs (using ROW_NUMBER() OVER ?). For instance, if I have the following I want to count only 1: FedIDNo SSN 123456789 987654321 123456789 998877654 Below is my SQL. SELECT dbo.ClientInfo.FedIDNo, dbo.People.SSN FROM dbo.Timesheets INNER JOIN dbo.ClientInfo ON dbo.Timesheets.ClientLinkID = dbo.ClientInfo.PeopleLinkID INNER JOIN dbo.People INNER JOIN dbo.PeopleLink ON dbo.People.PersonID = dbo....

stupid count question
Hi I have searched the forums and Google w/ no luck. Please help this is such a basic question that I cannot find the answer. 1.) I only have 1 cell (say A1) with multiple values (e.g. =123+125+125+....) which gives me a total of 373. 2.) In cell A2 only want to count the numbers with in cell A1 (e.g. 3) would be the answer. 3.) I do not want to use the =(Count(value1,value2,....). Because then I would have to enter the numbers in twice. I realize it is like the text count idea, but cannot figure out how to cross implement the idea. Thanks Rich -- Love programming but suck at it....

Counting number of items being added in a formula
I want to count the number of items that are being added together in a cell. For example if A1 had =3+5+7, A1 would sum to 15 and I would want B1 to show 3 for the number of items being added. What is the best way to capture this? It's going to depend a lot on the exact formula that you're using to add the numbers. Can you show an example of the formula please? If there is more than one possible formula style, then please show an example of each style. Rgds, ScottO "Lambtwo" <Lambtwo@lamb.com> wrote in message news:K5i9f.370924$tl2.237458@pd7tw3no... | I want t...

Count
I have a RealtorOffice table (pk companyID) and associated IndivRealtor table (fk CompanyID) that have field RealtorName & field RealtorTitle among other fields. I'm trying to find the number of individual realtors per office that have a title other than "Broker Associate". Thanks in advance. Here's what I have so far but it is not working... SELECT count(*) FROM Contact LEFT JOIN Company ON [Company].[CompanyID]=[Contact].[CompanyID] WHERE [Contact].[Title]<>"Broker Associate" Warren wrote: > I have a RealtorOffice table (pk companyID) and asso...

Counting rows, then counting values.
I have a lot of spreadsheets with many rows and columns of numbers. I need a way to find the highest value in each row, (mark it some how, bold the number maybe), then count the number of "highest" values are in each column. Is there an easy way to do this? Thank You, Michael Hi Michael You can use this to get the value =MAX(A1:A20) and this to count =COUNTIF(A1:A20,MAX(A1:A20)) -- Regards Ron de Bruin http://www.rondebruin.nl "Michael via OfficeKB.com" <forum@nospam.OfficeKB.com> wrote in message news:152907df2ac24b6ab6ee8d51d46958d9@OfficeKB.com... >...

Counting names in a column but counting duplicate names once
I have a column with people who contacted us during a given month. Some times the same person 2 to 3 time during the month. What funtion would I use to count this list but only count duplicate names to = 1. Thank you. 1 Jim 2 stan 3 stan 4 bob 5 Jim 6 Scott t = 4 Hi you can use the following array function (enter it with control & shift & enter, not just enter): =SUM(1/COUNTIF(A1:A10,A1:A10)) where your data is in the range A1:A10 check out http://www.cpearson.com/excel/duplicat.htm for more options and details -- Cheers JulieD check out www.hcts.net.au/tipsandtricks.htm...

Count Records in multiple tables
I am trying to get a count of Appointments from multiple tables using this statement - when I try to run it I get the unspecified expression error. Appointments: DCount("*",[dbo_REFERRAL_ORDER.APPT_DT] is not Null Or [dbo_ORDER_LOOKUP3.APPT_DT]is not null) The APPT_DT field in each table is a date field. The tables are joined by Orner Number, but the appointment date will populate in the different tables based on the data entry source. However, there could be data for the same order in both tables, so I cannot count each one indepentently & sum the result. ...

Counting a count
How do I count a count?? This is what im trying to do: I have a database with a table named tblMain and has incorporated everything within that table but contains info from about 8 other tables. I have not doesigned this database and it appears to have a very poor structure...anyway There are three fields involved in this process...'Request' (either 'dispensation', 'waiver' or 'dispensation and waiver'), 'Department' (which consists of 7 other drop down menu options) and 'RequestStatus' which contains the status of each request by another...

Count function causing error
I have a text box in the report footer that I want to count the instance "Y"s or "N"s in a text box in the detail section. It should be as easy as =-Sum([AttitudeComp]="Y"), but when I run the report I get an input box to enter the parameter value of AttitudeComp. I have rewritten the code several times, checked the spelling and even copied and pasted the name, but I keep getting the request for the value. If I enter the "Y" (or "N") I get a count of all the records. What am I doing wrong?? What is the name of the textbox in the deta...

Counting Cells (including Empty Ones)
Is there a way i can count teh number of cells between A5:A89 including the emply cells? I would like it to stay up-to-date automatically without my having to go back and do all the math myself. So if i add a few rows in between i will automatically count the new rows. It does that if there are numbers there but not if there are NO numbers. Thanks! Maybe the ROWS function. -- Jim Rech Excel MVP "Jacob" <anonymous@discussions.microsoft.com> wrote in message news:95E22AD7-4254-41B7-A4E3-A6407A6267BB@microsoft.com... | Is there a way i can count teh number of cells between ...

Count invalid data entries
I am using the following macro to identify invalid data entries in cells with data validation applied. Sub CheckOrder() ' Application.CommandBars("Formula Auditing").Visible = True ActiveSheet.CircleInvalid Sheets("Configuration").CircleInvalid Sheets("Parts_TakeOff").CircleInvalid MsgBox ("Check for Red Circled Invalid Data Entries on" & Chr(10) & " Configuration and Parts_TakeOff Sheets") End Sub Is there a way to count the number of invalid data entries (red circles) and write the number to a particular ce...

Count
I have two problems: 1) I need to count a row of 6 (AA4:AF4) -- but if it has zero for a quantity, I need "Count" not to include these in total. How do I get around this? 2) I am amortizing warranty. Is there a way to add "Count" to an "IF" statement? I don't have room in my spreadsheet to add a column for excel to count every month to see if it has amortized 6 months yet. Could I use "Count" and if "Count" = 6, then continue with the "IF" statement....all in one statement? Thanks in advance, -- Heather =COUNTIF(...

How to count the number of cells not empty?
I get a table from cell M2 to W200, and would like to count the number of cells not empty? which the cell equals to "". Does anyone have any suggestions? Thanks in advance for any suggestions Eric Try the formula =COUNTA(M2:W200) in any cell outside the table. "Eric" wrote: > I get a table from cell M2 to W200, and would like to count the number of > cells not empty? which the cell equals to "". Does anyone have any > suggestions? > Thanks in advance for any suggestions > Eric it counts the empty cell too, Do you have any ...

Smart List record count in 10.0 SP2
Hello, I'm wondering if anyone else has seen a situation in the standard smart list for Purchase Line Items returns a different line count in the window than on the bottom of the window in the status bar. For instance, a client requested a search using the view "Today's Expected Receipts", so the window shows 4 rows, but the status bar at the bottom shows 8. The search criteria look to be the same as in my local view. Trying it in my local view, I get the same results for other views under this object, for instance the window shows 13 rows, but the status bar shows ...

Counting the number of different entries in a column
Right! column A contains area codes (two digit numbers, eg. 30), column B customer numbers (eg 999999) The lists then go down listing orders. I want to count how many different customers have placed an order per area (not counting duplicates) Thanks for any help With the query area code in cell C1 enter the below formula. Please note that this is an array formula. You create array formulas in the same way that you create other formulas, except you press CTRL+SHIFT+ENTER to enter the formula. If successful in 'Formula Bar' you can notice the curly braces at both e...

select based on count
Hi all I have a table UserName PrinterName PageCount Message criss HP 7 Printed criss Xerox 6 Printed criss menolta 5 printed bob hp 3 printed bob hp 4 Printed I wanted to get thouse users whos Pages count is greater than 10 here criss's page count is 18 (7+6+5) greater than 10 but bob has only printed 7 lesser than 10 how to write a query to get the details of the user who's Pagecount is greater than 10 -- Message posted via SQLMonster.com http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200912/1 roma_victa via SQLMonster.com (u56444@uwe...

Cycle Count
Hi, Client running GP 10. I am setting up their cycle count schedules and have run into an issue that I can't get an answer for. Want to set up the count to give me the following quantity of items to count weekly: A - 15 Items B - 10 Items C - 5 Items I am unable to find a way to automate this. Any suggestions (besides buying other count software?). -- Jim Lines Sr. Microsoft Dynamics GP Applications Consultant Certified Microsoft Dynamics GP Specialist I don't think so Jim. The assumption behind cycle counting is that you'll count all your inventory at least once annual...

if, countif, count(if ???
I have 55 clusters, each cluster contains anywhere from 15 to 25 sites (varies), each site may start construction on the same date or may not. I need a formula that counts the sites per cluster that start in a range ie: (< = 4-8-06) , (<=4-15-06) (<=4-22-06) The Data set will contain over 800 sites so I am breaking it up week to week to show how many sites start construction and also need to make it cumulative: Trying to automate this so I can copy and paste the data the "formula" will pull from. From there I have a chart conditionally formatted red yellow green based on ...

Count cells matching two criteria (DATE & TEXT)
Hi, I work for a Truancy Reduction Center. We receive referrals from over 50 schools in the district for kids who are truant. We'd like to know the number of referrals a specific school sent us during a specific month. Referral Dates are in F4:F500 and School Names are G4:G500. This is what I've been trying: =SUMPRODUCT(--(TEXT('Client Log 09-10'!f4:f500,"yyyymm")="200910"),--('Client Log 09-10'!G4:G500="pacifica")) These functions work separately, but don't seem to want to play together. I just read a suggested relat...