473,788 Members | 3,030 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(ByV al Element As Xml.XmlElement) As Boolean

...

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

...

Dim DateToCompare As Date = Now.ToUniversal Time.Subtract(N ew TimeSpan(7,
0, 0, 0))
Dim DateStr As String = Format(DateToCo mpare, XmlDateTimeForm at)
Dim ExpiredStocks As Xml.XmlNodeList
' This doesn't work
ExpiredStocks = Element.SelectN odes("child::NS :Food[ExpireDate < " &
DateStr & "]", nsm)

...

Return True

End Function

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

And my xml data:

<Stocks>
<Stock ID="0001">
<ExpireDate>200 4-12-31T12:00:00Z</ExpireDate>
<AmountLeft>1 7</AmountLeft>
</Stock>

<!-- And so forth -->

</Stocks>
Nov 12 '05 #1
2 7753
"Echo 8" <er*******@hotm ail.com> wrote in message news:eM******** ******@tk2msftn gp13.phx.gbl...
' This doesn't work
ExpiredStocks = Element.SelectN odes("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.SelectN odes( _
String.Format( _
"//Stock[number(translat e(ExpireDate,'T Z:-', '.')) < number('{0}')]", _
DateTime.Now.To String( "yyyyMMdd.HHmms s") _
), _
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 XmlXPathExcepti on 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
13132
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 objects be considered equal? Is there a *general* way to test for date != datetime as well as 4.5 != 4.6?
2
13484
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) Thanx a lot in advance
0
1784
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 of xml created: <Date>2005-06-03T00:00:00.0000000+01:00</Date> I am based in the UK and my computer timezone is set to GMT (although the above data may have been created during DST).
2
1158
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 string) and set it initially to datetime.now (tostring) and the clicked event of a button compare that datetime.now - prevtime.. but the global variable has nothing in it... why? I thought it would be set when declared globally for some reason its...
2
2063
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, comparing the other, or is there some sort of compare function already in .net? For instance, I have these strings: str1: ,3,6,12,17, str2: ,7,8,12,
11
11422
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 have this: def test_sets(original_set, trans_letters): for pair in zip(original_set, trans_letters): if pair == pair: return False
1
7696
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 is a better way to achieve it for(i=0;i<arrayA.length;i++){ for(j=0;j<arrayB.length;j++){ if(arrayA==arrayB)
5
1895
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 matching array element. Otherwise -1 is returned. Here's what I have but I am going obviously wrong somewhere: #include <iostream> using namespace std; // This function compares values
2
1485
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 the backend access database table which has 2 columns RID and description. After comparing the flexgrid value with RID i need to select the rows which are similar for example i've no 8 and 24 in flexgrid now i need to compare this with access table...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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
10110
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
9964
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
8993
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
7517
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
6749
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.