Solved

Simple Xpath Query

Posted on 2012-03-26
10
806 Views
Last Modified: 2012-03-26
Hi,

I want to write some xpath that queries the event document below.

Here is my pseudo code

Give me all the Event/EventData/Data WHERE Event/Provider[@Name = "MYWCF Service" AND WHERE Event/TimeCreated[@SystemTime IS GREATER THAN "2012-03-23"

Here is my document.

<Event>
<System>
  <Provider Name="MyWCF Service" />
  <EventID Qualifiers="0">0</EventID>
  <Level>4</Level>
  <Task>0</Task>
  <Keywords>0x80000000000000</Keywords>
  <TimeCreated SystemTime="2012-03-23T10:43:02.000000000Z" />
  <EventRecordID>260031</EventRecordID>
  <Channel>Application</Channel>
  <Computer>TPR-ITSS-016.btn.opra.gov.uk</Computer>
  <Security />
  </System>
<EventData>
  <Data>2012-03-23 10:43:02,064 [14] DEBUG NHibernate.Engine.CascadingAction [(null)] - cascading to saveOrUpdate: TPR.Brunswick.Models.Milestone</Data>
  </EventData>
  </Event>
0
Comment
Question by:MrKevorkian
  • 6
  • 4
10 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 37765266
Event[System/Provider/@Name = "MYWCF Service"][translate(substring-before(System/TimeCreated/@SystemTime, 'T'), '-', '') > 20120323 ]/EventData/Data
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 37765269
just trying it out!
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 37765274
It gives me

Unexpected type - found '20120323' of type xs:integer, expected type xs:string
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37765293
OK, type casting error,
I assumed you were using XPath 1.0
Apparently you are using XPath 2.0
We can be more smart with the dates then

In which context are you using this?
In an XQuery or XSLT2?

And what exactly do you want the test with the date to do?
Does you XML matches your restriction?
So 1 minute past midnight in the morning of 23/2 is considered later than 23/2?
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 37765299
Hi,

I just evaluated your code using xml spy (latest version) .

In reality I will be running the code using C# 4.0 on Windows Server 2008.

I think XPath 1.0 will probably work.

Let me test it in a console app quickly.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37765367
note that the "=" test for strings is case sensitive
"MyWCF" will not match "MYWCF"
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 37765410
Hi,

Thanks alot got it working in my console (with a little tweak). This seems to work.

*[System[(Provider/@Name = 'MyWCF Service') and TimeCreated[@SystemTime >= translate("2008-02-21", '-', '')]]]/EventData/Data
0
 
LVL 1

Author Closing Comment

by:MrKevorkian
ID: 37765411
super quick answer!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37765431
welcome,

the construct with the time does not seem right to me in your tweaked version

you are doing the translate on the fixed string, the only difference with the numeric I had is that the result is a string, but putting quotes has the same effect "20080221"
I wonder how dierct SystemTime could work given that XPath1 only knows about strings and numeric
might be that msxml does the right thing
... but hey, if it works, it works :-)
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 37765438
Thanks, I will have another look at the time comparison as you have suggested.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question