Solved

Simple Xpath Query

Posted on 2012-03-26
10
816 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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