Hpw to know level tag position

I need to know a way for knowing tag position in a xml like this:

     <AAA>
          <BBB>
              <CCC>
                    <DDD_1/>
                    <DDD_2/>
                    <DDD_3/>
              </CCC>
          <BBB/>
     </AAA>
I need to get that AAA = 1, BBB=2,CCC=3,
DDD_1=4, DDD_2=4,DDD_3=4

thanks for help.
Sam 


0
none6869 (6)
7/22/2007 7:12:04 AM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
437 Views

Similar Articles

[PageSpeed] 31

sam wrote:
> I need to know a way for knowing tag position in a xml like this:
> 
>      <AAA>
>           <BBB>
>               <CCC>
>                     <DDD_1/>
>                     <DDD_2/>
>                     <DDD_3/>
>               </CCC>
>           <BBB/>
>      </AAA>
> I need to get that AAA = 1, BBB=2,CCC=3,
> DDD_1=4, DDD_2=4,DDD_3=4

count($n/ancestor::node()) where $n is your node. So with a stylesheet 
you could do:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output method="text"/>

   <xsl:template match="/">
     <xsl:apply-templates select="//*"/>
   </xsl:template>

   <xsl:template match="*">
     <xsl:value-of select="concat(name(), ' = ', 
count(./ancestor::node()))"/>
     <xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
7/22/2007 11:28:22 AM
> Martin Honnen
> count($n/ancestor::node()) where $n is your node. So with a stylesheet
Okey, but I am using XML .Net control for handling xml files.
So, how to get this value in csharp code ?

Sam

"Martin Honnen" <mahotrash@yahoo.de> a �crit dans le message de news: 
Oru9qNFzHHA.1184@TK2MSFTNGP04.phx.gbl...
> sam wrote:
>> I need to know a way for knowing tag position in a xml like this:
>>
>>      <AAA>
>>           <BBB>
>>               <CCC>
>>                     <DDD_1/>
>>                     <DDD_2/>
>>                     <DDD_3/>
>>               </CCC>
>>           <BBB/>
>>      </AAA>
>> I need to get that AAA = 1, BBB=2,CCC=3,
>> DDD_1=4, DDD_2=4,DDD_3=4
>
> count($n/ancestor::node()) where $n is your node. So with a stylesheet you 
> could do:
>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="1.0">
>
>   <xsl:output method="text"/>
>
>   <xsl:template match="/">
>     <xsl:apply-templates select="//*"/>
>   </xsl:template>
>
>   <xsl:template match="*">
>     <xsl:value-of select="concat(name(), ' = ', 
> count(./ancestor::node()))"/>
>     <xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 


0
none6869 (6)
7/22/2007 5:19:40 PM
sam wrote:
>> Martin Honnen
>> count($n/ancestor::node()) where $n is your node. So with a stylesheet
> Okey, but I am using XML .Net control for handling xml files.
> So, how to get this value in csharp code ?

Using System.Xml.XmlDocument you can do it like this:

       XmlDocument xmlDocument = new XmlDocument();
       xmlDocument.Load(@"file.xml");
       foreach (XmlNode element in xmlDocument.SelectNodes(@"//*"))
       {
         Console.WriteLine("{0} = {1}.", element.Name, 
element.SelectNodes(@"ancestor::node()").Count);
       }

If you are using the ASP.NET XML control then use the stylesheet I 
posted in my first reply.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
7/23/2007 1:13:45 PM
Martin, thank you very very very much for all samples that works fine.

Sam 


0
none6869 (6)
7/23/2007 3:06:26 PM
Reply:

Similar Artilces:

Linking information from Account to Contact level
Hello. I am trying to link information from an account to a contact and don't seem to understand it! Here is our situation; our account as some standard info; address, business phone, fax, etc. For some reason when creating a new contact WITHIN that account the information we want is filled in except for fax number. Why?? Also, I want to create two other attributes (Bulk Email and Bulk Mail - both Allow or Do Not Allow) and want that information to filter down from the account level to the contact when creating a new contact. Basically, I'm asking how do you insert (and l...

set cursor position to the last character of textbox
Hello, I create a textbox from Drawing toolbar. I add some text to it. Then, I want to select it and set cursor position to the last character. Can someone supply the VBA code to do this? ...

does anyone know how to expand the field on an axis
Please use the white space to give a fuller message. The term 'expand the field' is unclear. best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "Theresa" <Theresa@discussions.microsoft.com> wrote in message news:5A4BA3F9-109C-4F05-9615-97293C99C627@microsoft.com... > I am trying to add more fields to my x axis than the 7 allowed. My chart is short fields needed, it is almost as if I need a secondary axis but I am not using a pivot chart. All the information appears on the chart blank because I am not able to load the info...

do you know dimigo ?
�� ���������������������������� xbox is so good but psp is better ~ ...

Changing the Security Level
How can I change security levels for atytachments in Outlook 2003? I keep changing the security level in Outlook 2003 to Medium, Outlook keeps changing it back to High. I posted a question concerning opening a Word document from within Outlook on 12/13. I must have stumped everyone 'cause no replied. So I found the only way is to create a Task and insert an attachment which would be a Word document. Now Outlook won't al;low me to change the security to medium and it removes the Attachments. Any ideas?? James Your post doesn't make much sense; 1) The security level your are ref...

Opening a dialog in a more helpful position
I have the following line in a button event on FormA: DoCmd.OpenForm "FormB", WindowMode:=acDialog This opens FormB in the EXTREME upper left of the Access window, where the user will probably miss it. Is there a way to make FormB open in the middle of FormA? Thanks, Tom If you open the form in Design View, and go to properties, on the Format tab, there is an option to "Auto Center". Set that to yes and the form will automatically open to the middle of your screen. ...

Table of Contents
Having used autogenerated Table of Contents feature in Word for some little while I would like to produce a Publisher 2003 document with the same feature. No idea how to achieve this as it seems to be an unsupported feature in Publisher. Suggestions please ? Tonto <Tonto@discussions.microsoft.com> was very recently heard to utter: > Having used autogenerated Table of Contents feature in Word for some > little while I would like to produce a Publisher 2003 document with > the same feature. No idea how to achieve this as it seems to be an > unsupported feature in Publisher....

I know why my fonts are changing! Workaround?
I posted yesterday that replies from people using Eudora come back in a different font (Times New Roman) than I sent them out. I've researched and discovered this article. http://support.microsoft.com/default.aspx?scid=kb;en-us;223878 Outlook changes the font to Times New Roman 10pt whenever a message changes from Plain Text to HTML even if it isn't the default HTML font. Somewhere in the process of send/receive/reply/receive this must be happening. I'm sure this has been addressed here before since the article is for OL2000, but I've been using Eudora so this is the first...

How to locate a PC running a know service?
I'm working on a client-server application. The server is installed on a machine on the LAN. Then, the installation CD is inserted into a client PC. I'm trying to locate the server programmatically (from the autorun.exe app on the CD). One option I'm doing is enumerating all computers on the LAN, and then enumerating all services on each computer, looking for my service. This works for many cases. I'm trying to use "connect" with *every* IP within the subnet mask -- but it takes *forever* for each connect to timeout (about 20 seconds per connect). Is there...

Assigning more than one tag to tag property
It it possible to assign more than one tag to a control's tag property, so that you can assign it to multiple groups? I tried separating tags by semicolons or commas but that seemed to render each tag obsolete. Kurt interesting you should ask that. I wrote a class module that manages multiple values in tags, but I don't have it here at work. Post back so I can track the thread and if I can find it over the weekend, I will post back with the code and how to use it Monday. -- Dave Hargis, Microsoft Access MVP "HeislerKurt@gmail.com" wrote: > It it possible to as...

Vouchers (Gift Cards) and Price levels
When we sell a gift card to a customer who is set at price level A, B, C or who has a fixed % discount, the $ amount you enter when "activating" the gift card will change to 0$ for level A, B, or C and to the corresponding discount % for those with a fixed discount. Now I know it is easy to simply re-enter the correct amount; however, it is another step for cashiers to miss and/or make an error. Does anyone know a way around this or a configuration setting I am missing? I have not yet installed V1.3. I am waiting 'till the holiday season has passed. Set the A, B &...

do you know??
hi I have a problem I had made a programm deal with database I had created it manually by microsoft access. I want the programm make the database automatically when it run on every computer?? second did every computer run this programm have microsoft access ??? goodbye thank you ??? 1. You should just ship the mdb file with your program. 2. you don't need to have access installed on all the computers just the odbc/ado drivers for access. AliR. "mohaz" <mohaz14@yahoo.com> wrote in message news:1187291340.459954.57930@k79g2000hse.googlegroups.com... > hi >...

Any one know what I should do to get this fixed?
Event Type: Warning Event Source: MSExchangeIS Event Category: General Event ID: 9548 Date: 5/16/2006 Time: 5:01:07 PM User: N/A Computer: NORDICS1 Description: Disabled user /o=NORDICAIR/ou=first administrative group/cn=Recipients/cn=sskinner does not have a master account SID. Please use Active Directory MMC to set an active account as this user's master account. For more information, click http://www.microsoft.com/contentredirect.asp. Assign "Self" to the account. Nue "Steve MCSE MCV A+ NET+" <stvnchrs@adelphia.net> wrote in message news:E6OdnUIqtO...

Item-Level Recover for Public Folders
Hi, i'm testing Exchange 2010 with SC DPM 2010 RC. For item-level restoring MS DPM suggest to use Recovery Database in Exchange 2010. It's works fine with Mailbox Databases. In Exchange we have limit to one Public Folder Mailbox Database. After backup is restoring to Recovery Database, it can not be mounted. If dismount Public Folder Database, Recovery Database bring mounted. Anybody have ideas to implement item-level restore for Exchange Public Folders? If you want to recover an item from a database to another database it is must that both of them need to ...

How to know when a shortcut key is already assigned
When recording a macro in Word the dialog box that lets you assign a shortcut key to the new macro shows you if any other command is presently assigned to the key combination you'd like to choose. The equivalent dialog box in Excel is different from the one in Word and does not appear to have this useful feature. Hence you may unknowingly override some built-in command when assigning a shortcut key to a macro in excel. Word also has a nifty feature whereby you can produce a listing of all the built-in commands, along with there currently assigned shortcut keys. Excel does not seem to h...

Clickable pie chart
I want to do a 3D pie chart embedded in a work sheet and allow each piece if the pie to be 'clickable' i.e run a designated macro when clicked. One way that occurs to me (but hard in itself) would be to put an invisible cover (autoshape) over the piece and then assign the macro to it; but how would I go about matching its size and shape to the correct dimension and position of the pie peice? Another compromise (if as I think my ideal way is impossible) would be to try and detect the label position (less variable than the pie piece and a convenient rectangle) and then place an i...

Net Display does not remember left and top position settings
When I log out of POS the Net Display defaults from the assigned left and top settings back to original settings so I have to adjust every time I open. How do I get these settings to remain? A couple of points: 1. The size of the Display holds to the settings I assigned. 2. I am trying to run both POS screen and Net Display on the same screen for dem purposes. I read someone else here had that problem. Fixed by logging in as someone with local admin priveleges, making the changes, then logging back on as the user. Might be worth a try. "AB" wrote: > When I log out of PO...

I would like to know if I can make a polar chart with excel
I need to make a grafic of Ø Vrs. K*SenØ, but the chart must be polar Hi, Here are some resources that may help you out. Check out FunChrt6.zip on Stephen Bullen's site http://www.bmsltd.ie/Excel/Default.htm http://www.stfx.ca/people/bliengme/ExcelTips/Polar.htm http://www.andypope.info/charts/polarplot.htm Cheers Andy mario567 wrote: > I need to make a grafic of Ø Vrs. K*SenØ, but the chart must be polar -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info ...

Customize list of activities, status and task level
Hi all, I'm just using MS CRM 1.2.I would to know how can i customize(add new entry, remove existing entry) default list of activities, activities status, activities priority level. Thak for help! Unfortunately, in v1.2 there is no supported method for making any customizations to any of the Activities. Some changes are allowed in v3.0, but you still cannot change the 6 base Activity "types". -- Matt Parks MVP - Microsoft CRM "Guillaume TOURE" <GuillaumeTOURE@discussions.microsoft.com> wrote in message news:3F73F60A-544E-4375-A395-3C04753E7D3D@microsoft.c...

Do You Know If She Is Cheating?
We hear that some women say that their men are cheating them from time to time. Sometimes they are right that their men are really cheating them. However, the fact is that they will be wrong most of the time. There are even men complaining that their ladies keep accusing them of cheating but in fact they are not. The interesting question is that: Do women also cheat men? http://www.articlesofinformation.com/Category/Dating/146 ...

I don't know! Message passing
I derived class from CButton in order to create Group box (and I did it successfully). There are combo box and button in group box. Now I programmatically create that GroupBox on property sheet. When I click button in GroupBox I would like to have handling code in property sheet. How to create message maps? Is there any link with explanation. Thanx, T Is it possible to add message handler to programatically created control at all? I tried with simple dialog and it didn't work. "news.microsoft.com @hotmail.com>" <ba_tornado<remove this> wrote in message news:eULfcO...

Position of Control in Dialog Box ?
Hi guys, How do I get the top-left position of a control in a dialog box ? I tried GetWindowRect() but it's in screen coordinates. I want to create a static frame then go like this: (pseudo code) rect = client rect of static control fill rect If I use GetClientRect it's at 0,0, so I need the top-left position so I can offset the rect. Thanks. You can use ScreenToClient to convert it to client coordinates. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Robert A." <invalid@invalid.org> wrote in message news:mwN_b.75089$ac.17794820@news4.srv.hcvlny.cv.net... | ...

Service Level Agreements
...

Does anyone know?
Hi We have just switched to Excel 2002. Does anyone know how I can get the "=" sign to remain in the toolbar instead of having to click the "Fx" every time to bring it up when I want to input a formula? The older excel was able to do this. Thanks Lyle Hi Lyle Don't think that's possible. Anyway, the quickest way to start a formula is simply to just type = . Or + if you have a keyboard where = is awkward to get to. You get uglier formulae that way though. HTH. Best wishes Harald "LYLE MOYER" <lemoyer@verizon.net> skrev i melding news:edofe....

Positive & negitive numbers in conditional formatting statement
I know this will be a easy one for somebody, in a report field I would like to highlight the money amounts (clear/white) for zero, red for neg Number (money owed) and green for credited money. Zero works great, but it seems that it would tell positive from negitive numbers. -- Frank Hi Frank Use condidtional formating HTH -- Wayne Manchester, England. "Frank" wrote: > I know this will be a easy one for somebody, in a report field I would like > to highlight the money amounts > (clear/white) for zero, red for neg Number (money owed) and green for > cred...