0

I need to filter the response of a SOAP web-service. Since SOAP is based on XML, I am thinking about using libxml2, but I am not able to understand how to write an XPath expression to achieve the desired result.

At the end of the message you'll find an example of the response, where two NotficationMessages are sent, one has a topic tns1:RuleEngine/LineDetector/Crossed , the other one has topic tns1:RuleEngine/CellMotionDetector/Motion .

I am trying to write the following XPath expressions:

  • match any NotficationMessage whose topic is tns1:RuleEngine/LineDetector/Crossed
  • match any NotficationMessage whose topic is tns1:RuleEngine//.
  • match any NotficationMessage whose topic is everything but tns1:RuleEngine//.

All the examples I found match on attributes, not the content of child elements.

So I'm asking.

  1. are this kinds of matching doable with libxml2 or with XPath in general?
  2. can you please give me a hint about writing the XPath expressions?
<?xml version="1.0" encoding="UTF-8"?>
  <SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:wsa="http://www.w3.org/2005/08/addressing" 
    xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" 
    xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" 
    xmlns:tet="http://www.onvif.org/ver10/events/wsdl" 
    xmlns:tns1="http://www.onvif.org/ver10/topics"
    xmlns:tt="http://www.onvif.org/ver10/schema">
    <SOAP-ENV:Header>
      <wsa:Action>  http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesResponse
      </wsa:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
      <tet:PullMessagesResponse>
        <tet:CurrentTime>
          2008-10-10T12:24:58
        </tet:CurrentTime>
        <tet:TerminationTime>
          2008-10-10T12:25:58
        </tet:TerminationTime>
        <wsnt:NotificationMessage>
          <wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">
            tns1:RuleEngine/LineDetector/Crossed
          </wsnt:Topic>
          <wsnt:Message>
            <tt:Message UtcTime="2008-10-10T12:24:57.321Z">
              <tt:Source>
                <tt:SimpleItem Name="VideoSourceConfigurationToken"
                               Value="1"/>
                <tt:SimpleItem Name="VideoAnalyticsConfigurationToken"
                               Value="2"/>
                <tt:SimpleItem Value="MyImportantFence1" Name="Rule"/>
              </tt:Source>
              <tt:Data>
                <tt:SimpleItem Name="ObjectId" Value="15" />
              </tt:Data>
            </tt:Message>
          </wsnt:Message>
        </wsnt:NotificationMessage>
        <wsnt:NotficationMessage>
          <wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">
           tns1:RuleEngine/CellMotionDetector/Motion
          </wsnt:Topic>
          <wsnt:Message>
            <tt:Message UtcTime= "2010-10-20T12:24:57.628">
              <tt:Source>
               <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
               <tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
               <tt:SimpleItem Name="Rule" Value="MotionInDefinedCells"/>
              </tt:Source>  
              <tt:Data>
               <tt:SimpleItem Name="IsMotion" Value="true"/>
              </tt:Data>
            </tt:Message>
          </wsnt:Message>
        </wsnt:NotficationMessage>
      </tet:PullMessagesResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
nwellnhof
  • 32,319
  • 7
  • 89
  • 113
Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58

1 Answers1

0

All you need are basic XPath expressions using location paths and predicates:

  1. match any NotficationMessage whose topic is tns1:RuleEngine/LineDetector/Crossed

    //wsnt:NotificationMessage[wsnt:Topic = 'tns1:RuleEngine/LineDetector/Crossed']
    
  2. match any NotficationMessage whose topic is tns1:RuleEngine//.

    //wsnt:NotificationMessage[wsnt:Topic = 'tns1:RuleEngine//.']
    
  3. match any NotficationMessage whose topic is everything but tns1:RuleEngine//.

    //wsnt:NotificationMessage[wsnt:Topic != 'tns1:RuleEngine//.']
    
nwellnhof
  • 32,319
  • 7
  • 89
  • 113