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.

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

1 Answer 1

1

Try this:

//*[local-name()='EventData' and ./*[local-name()='Data']
[@Name="ObjectName"and 
(ends-with(text() ,".exe") or ends-with(text() ,".txt"))]]
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.