Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the xml file which I made a XPath request for. But it works only without the xmlns-namespace. Can You help me with the adding correct namespace qualifier (I have errors)?

xml:

<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'> 
  <EventData> 
    <Data Name="ObjectServer">Security</Data>  
    <Data Name="ObjectType">File</Data>  
    <Data Name="ObjectName">C:\Temp\Project1.txt</Data> 
  </EventData> 
</Event>

XPath:

*[EventData[Data[@Name="ObjectName" and (ends-with(text() ,".exe") or ends-with(text() ,".txt"))]]]

P.S. I'm using C++. My code based on this example from msdn. But I think its not significantly, because of I'm checking this request with online XPath tester.

Thanks.

share|improve this question
What language are you using on the higher level? – choroba Oct 24 '12 at 21:25
I think you should check here: stackoverflow.com/questions/536441/… It seems the same question. – Duccio Fabbri Oct 24 '12 at 22:12
I used local-name(), but code doesn't working - filter dont work. – pnt_of_view Oct 24 '12 at 23:10

1 Answer

up vote -1 down vote accepted

Try this:

//*[local-name()='EventData' and ./*[local-name()='Data']
[@Name="ObjectName"and 
(ends-with(text() ,".exe") or ends-with(text() ,".txt"))]]
share|improve this answer
Thanks, its work fine! – pnt_of_view Oct 25 '12 at 6:36
This can become more generic selecting any 'objectname' under any nodes defeating the purpose of namespaces in the firstplace. Although this worked for the user, IMHO, the correct solution would be to use a xpath query which would filter the node based on the path in the matching namespaces. – ChanGan Dec 13 '12 at 11:35
I don't understand why "-1". As I posted in my comment, this is just a rielaboration of another answer, which has no negavive feedbacks. If I deserve a downvote, why not for stackoverflow.com/questions/536441/… ? If you have a better solution, please post it. – Duccio Fabbri Dec 17 '12 at 15:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.