1

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.

pnt_of_view
  • 33
  • 1
  • 5

1 Answers1

1

Try this:

//*[local-name()='EventData' and ./*[local-name()='Data']
[@Name="ObjectName"and 
(ends-with(text() ,".exe") or ends-with(text() ,".txt"))]]
Duccio Fabbri
  • 998
  • 1
  • 10
  • 21
  • 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 http://stackoverflow.com/questions/536441/xpath-namespace-driving-me-crazy ? If you have a better solution, please post it. – Duccio Fabbri Dec 17 '12 at 15:20