473,785 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath get the max value

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.
Apr 27 '06 #1
3 23948


beachboy wrote:
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)]

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 27 '06 #2
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.SelectSingl eNode( /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!!!

"Martin Honnen" <ma*******@yaho o.de> ???
news:O0******** ******@TK2MSFTN GP05.phx.gbl ???...


beachboy wrote:
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)]

--

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

Apr 28 '06 #3


beachboy wrote:

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
SelectSingleNod e you will get one attribute node or null, with
SelectNodes you will get a node list with attribute nodes.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6826
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
7
16660
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
4
21210
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
9
2155
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
2
2579
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or place holders, as two examples below: Example - File type 1
3
4980
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
8
13200
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A <pnode may contain this text: <p> Test1<br/>
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.