|
-
Jun 28th, 2011, 02:40 AM
#1
Thread Starter
Member
xml date compare
Hi All,
I want to write a function that select some of xml nodes from a xml file
that xml file has a attribute is date 20/06/2011 12:00:00 PM
if i want to select all the node that is before 20/06/2011.
i know sql query has >>> date LIKE "20/06/2011%"
does xpath or .net has kind of method
thank you
-
Jun 28th, 2011, 02:48 AM
#2
Re: xml date compare
If you want to compare dates temporally then you will need to create Date objects from the Strings contained in the XML. Depending on the circumstances, you might use CDate, Date.Parse, Date.ParseExact, Date.TryParse or Date.TryParseExact. You can then compare them like you would any other Dates, using mathematical operators.
-
Jun 28th, 2011, 06:15 PM
#3
Thread Starter
Member
Re: xml date compare
sorry, my question was abit confuse.
I want something like this>>
Code:
xmlnodelist = xmldoc.SelectNodes("/namelist/names[@dir='20/06/2011 12:00:00 PM']/name")
that means it selects all the name nodes which @dir = 20/06/2011 12:00:00 PM
Now if I want to select all the name nodes which @dir LIKE '20/06/2011%' << I know the xml doesnt have LIKE, does any other simliar method that xml provide
-
Jun 28th, 2011, 07:12 PM
#4
Re: xml date compare
you could use LINQ to XML:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xml = _
<?xml version="1.0" standalone="no"?>
<root>
<nameList>
<name dir="20/06/2011 12:00:00 PM">name1</name>
<name dir="20/06/2011 01:00:00 PM">name2</name>
<name dir="20/06/2011 02:00:00 PM">name3</name>
<name dir="21/06/2011 12:00:00 PM">name4</name>
<name dir="21/06/2011 02:00:00 PM">name5</name>
</nameList>
</root>
MsgBox((From node In xml...<nameList>.<name> Where [email protected]("20/06/2011") Select node.Value) _
.Aggregate(Function(current, s) current & ", " & s).ToString)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|