?
Solved

Simple Xpath Query

Posted on 2012-03-26
10
Medium Priority
?
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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