Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2006

Tip: Looking for answers? Try searching our database.

XPath get the max value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
beachboy - 27 Apr 2006 09:08 GMT
can we get the max value of element from xpath

e.g: Xpath Query Expression: /Books/Book[@id='3'] to select XMLNode which id
is "3"

Can I use Xpath to get the MAX Book id?

Thanks in advanced.
Martin Honnen - 27 Apr 2006 13:27 GMT
> can we get the max value of element from xpath
>
> e.g: Xpath Query Expression: /Books/Book[@id='3'] to select XMLNode which id
> is "3"
>
> Can I use Xpath to get the MAX Book id?

This XPath expression

  /Books/Book[not(@id <= preceding-sibling::Book/@id) and not(@id <=
following-sibling::Book/@id)]

selects the Book element with the maximum id attribute value.

If you want to select the attribute itself then use

  /Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
../following-sibling::Book/@id)]

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

beachboy - 28 Apr 2006 02:54 GMT
Thanks Martin,

I want to clarify my understanding..

I can get a XmlNode which has a max id attribute value for below syntax:
XmlNode node = doc.SelectSingleNode( /Books/Book[not(@id <=
preceding-sibling::Book/@id) and not(@id <= following-sibling::Book/@id)] )

but how to implement below expression? what type will return? XmlNode or
just a value of id
/Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
../following-sibling::Book/@id)]

Thanks again!!!

> > can we get the max value of element from xpath
> >
[quoted text clipped - 14 lines]
>    /Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
> ../following-sibling::Book/@id)]
Martin Honnen - 28 Apr 2006 12:53 GMT
> but how to implement below expression? what type will return? XmlNode or
> just a value of id
>  /Books/Book/@id[not(. <= ../preceding-sibling::Book/@id) and not(. <=
>  ../following-sibling::Book/@id)]

That XPath expression selects attribute nodes with name id. Thus with
SelectSingleNode you will get one attribute node or null, with
SelectNodes you will get a node list with attribute nodes.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.