473,499 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating or comparing xs:dateTime values in xpath queries with SelectNodes

Is there a simple way of compare dates? I am trying to create a list of
perishable stock in an inventory that is near or past its expiration date.

I've tried telling it to compare a node's value with a DateTime string, but
that doesn't work.
I've assumed that it is easier to manipulate today's date instead of the
date in my ExpireDate element.

Thankyou in advanced for taking the time to read this and possibly helping
me

Echo 8

----------------------------------------------------------------------------
--------------------------------

My Code:

Public Function FromElement(ByVal Element As Xml.XmlElement) As Boolean

...

Const XmlDateTimeFormat As String = "yyyy-MM-dd\THH:mm:ss\Z"

...

Dim DateToCompare As Date = Now.ToUniversalTime.Subtract(New TimeSpan(7,
0, 0, 0))
Dim DateStr As String = Format(DateToCompare, XmlDateTimeFormat)
Dim ExpiredStocks As Xml.XmlNodeList
' This doesn't work
ExpiredStocks = Element.SelectNodes("child::NS:Food[ExpireDate < " &
DateStr & "]", nsm)

...

Return True

End Function

----------------------------------------------------------------------------
--------------------------------

And my xml data:

<Stocks>
<Stock ID="0001">
<ExpireDate>2004-12-31T12:00:00Z</ExpireDate>
<AmountLeft>17</AmountLeft>
</Stock>

<!-- And so forth -->

</Stocks>
Nov 12 '05 #1
2 7728
"Echo 8" <er*******@hotmail.com> wrote in message news:eM**************@tk2msftngp13.phx.gbl...
' This doesn't work
ExpiredStocks = Element.SelectNodes("child::NS:Food[ExpireDate < " &
DateStr & "]", nsm)
Could you describe in a little more detail what doesn't work about
that line?

Does it return an empty XmlNodeList, because the example XML
included contains no namespaces or elements with a local name
of Food? Or have those details just been left out of the example?

(I can't be of much help identifying why the XPath expression doesn't
work when it's inconsistent with the XML.)

Does it throw an exception claiming that there is an invalid qualified
name in the XPath expression, because it sees the colons in the
DateStr as separating a prefix from a local name? This would be
due to the XPath expression missing ' (single-quotes) around the
DateStr to make it appear as a literal string to XPath.
I've assumed that it is easier to manipulate today's date instead of the
date in my ExpireDate element.
You're going to have to manipulate the date in your ExpireDate
element, because Relational Expressions in XPath 1.0 can't
compare strings. Relational operators in XPath require their
operands to be converted to numbers.

http://www.w3.org/TR/xpath#NT-RelationalExpr
Is there a simple way of compare dates?


Something like the following may work for you (untried and w/o
warranty, as the details will depend on what your actual XML is),

ExpiredStocks = Element.SelectNodes( _
String.Format( _
"//Stock[number(translate(ExpireDate,'TZ:-', '.')) < number('{0}')]", _
DateTime.Now.ToString( "yyyyMMdd.HHmmss") _
), _
nsm )

The concept is to strip the dashes, colons and trailing Z, and
change the T to a decimal point, then compare it against a
similarly-formatted DateTime parameter.
Derek Harmon
Nov 12 '05 #2
Sorry about that. I tried to simplify everything until just the "essence" of
what I was trying to get accross. I must have put Food instead of Stock when
I was typing it. Anyway, it does come up with a XmlXPathException about that
qualified name thing. I'm not very experienced with .Net, xpath, or xml, made
obvious by the code I put in the first post.

Anyway, thanks for your swift reply. It's solved my problem.
Nov 12 '05 #3

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

Similar topics

16
13100
by: Donnal Walter | last post by:
I was very surprised to discover that >>> import datetime >>> x = datetime.date(2004, 9, 14) >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15) >>> print x == y True How can these two...
2
13472
by: prashanth | last post by:
Hi all, I am unable to write a javascript which will allow me to compare datetime entered by the user with the current datetime.( i.e the usertime should be less than or greater than currenttime)...
0
1772
by: eastlands | last post by:
Not sure if this is an xml or a ado.net question: I have created an xml document from a .net dataset which contains a DateTime column, however all the time elements are set to 00:00:00. example...
2
1142
by: Stephen | last post by:
Hi, I dont know whether I am doing this correctly or not. I want some procedure to fire when the time b/w the last and the current request is > 15 min I declared a global variable (txtPrev as...
2
2043
by: darrel | last post by:
I have two comma delimted strings that I need to compare individual values between the two. I assume the solution is likely to put them into an array? If so, do I need to loop through one,...
11
11396
by: John Salerno | last post by:
I'd like to compare the values in two different sets to test if any of the positions in either set share the same value (e.g., if the third element of each set is an 'a', then the test fails). I...
1
7681
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
5
1866
by: SneakyElf | last post by:
I need to write a function where the third parameter points to an address whose dereferenced value equals one of the array element's value, then the the function returns the index of the first...
2
1459
by: sumuka | last post by:
Hello Everyone, I'm doing a project in VB 6.0 and i've a flexgrid which contains some numerical values in it's cell now i need to compare these values present in flexgrid with the values in...
0
7134
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,...
1
6905
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...
0
5485
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,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
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...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.