|
-
Aug 7th, 2003, 12:11 AM
#1
Thread Starter
Frenzied Member
XPath - Resolved.
Right, I'm building a calendar selection. The month & year are known.
Now, assuming I have an XML structure like this (from Sql Server):
Code:
<root>
<item>
<startdate>2003-08-01T16:00:00</startdate>
<enddate>2003-08-03T16:30:00</enddate>
<caption>Blah</caption>
<url>www.blah.com</url>
<color>navy</color>
</item>
<item>
<startdate>2003-08-01T10:00:00</startdate>
<enddate>2003-08-07T11:30:00</enddate>
<caption>Blah Again</caption>
<url>www.blah.com</url>
<color>silver</color>
</item>
</root>
So, with a loop through the days of the month, I've got the date (time can be ignored). Now what I've got to do, is check if the date falls within a date range.
For example, in the above XML, lets say the date is 20030802. It falls between the start and end dates of both items. Now, I need the colors for both of these items. If the date was 20030804, only the second item's color is required.
The problem I'm having is that I can't figure out how to use two child nodes in one predicate, using the substring function. This is all being done in C#, btw, and looping through each node in the Xml document & manually checking is easy enough, but why write all that code if you can get it with one XPath query? 
Thanks,
Brian
[Edit] Dates were in the wrong format.
Last edited by axion_sa; Aug 7th, 2003 at 01:07 AM.
-
Aug 7th, 2003, 01:03 AM
#2
Thread Starter
Frenzied Member
No worries - got it:
Code:
root/item[substring(translate(startdate, '-', ''), 1, 8) = '2003-0801'][substring(translate(enddate, '-', ''), 1, 8) <= '2003-0801']
-
Feb 8th, 2007, 10:11 AM
#3
Re: XPath - Resolved.
I don't like digging up old threads but I've got a problem similar, but simpler, that the one you had and I'm wondering if you can figure out what I'm doing wrong. If you take a look at this thread I took the solution you gave in this thread and tried
("//privatemessage/"[substring(translate(datestamp, '-', ''),1,10) > '20070101']")
but got nothing. Any ideas?
-
Feb 8th, 2007, 11:58 AM
#4
Re: XPath - Resolved.
Did you copy that xpath string wrong or is that actually a syntax error?
(The " after //privatemessage/)
-
Feb 8th, 2007, 12:02 PM
#5
Re: XPath - Resolved.
Copied it wrong. In my program it looks like
VB Code:
Set oxmlNodeList = XMLdoc.documentElement.selectNodes("//privatemessage/" _
& "[substring(translate(datestamp, '-', ''),1,10) > '20070101']")
which equates to
("//privatemessage/[substring(translate(datestamp, '-', ''),1,10) > '20070101']")
-
Feb 8th, 2007, 12:04 PM
#6
Re: XPath - Resolved.
Try
VB Code:
Set oxmlNodeList = XMLdoc.documentElement.selectNodes("//privatemessage" _
& "[substring(translate(datestamp, '-', ''),1,10) > '20070101']")
Note that the [square brackets] are very similar to a 'WHERE' clause in SQL. So the / that I removed would not have much meaning unless a node were specified after it.
You might also want to try gt instead of > if the modification didn't work.
-
Feb 8th, 2007, 12:20 PM
#7
Re: XPath - Resolved.
 Originally Posted by mendhak
Try
VB Code:
Set oxmlNodeList = XMLdoc.documentElement.selectNodes("//privatemessage" _
& "[substring(translate(datestamp, '-', ''),1,10) > '20070101']")
Note that the [square brackets] are very similar to a 'WHERE' clause in SQL. So the / that I removed would not have much meaning unless a node were specified after it.
You might also want to try gt instead of > if the modification didn't work.
Your code as posted worked. Thanks very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|