Search code examples
xmlxpathpredicateslash

Xpath match node with slash in data using predicate


Problem originated while using SoapUI to validate xml response data. I transfered the problem to XPath Visualizer so I could work through the issues.

Using an Xpath query I want to return the b:AccountActivity node that has the child node b:ActivityDescription value equal to '7.75000%10/30-11-10 $1602' from the xml excerpt below.

This is my xpath query:

//b:AccountActivity[b:ActivityDescription = "7.75000%10/30-11/10    $1602"]

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <RetrieveAccountActivityResponse xmlns="http://tempuri.org/">
         <RetrieveAccountActivityResult xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:key xmlns:b="http://schemas.datacontract.org/2004/07/IntegratorSuite.DataContracts">
               <b:CurrentPage>0</b:CurrentPage>
               <b:Direction>Ascending</b:Direction>
               <b:PageSize>50</b:PageSize>
               <b:SortByParameter i:nil="true"/>
               <b:TotalEntries>4</b:TotalEntries>
               <b:TotalPages>1</b:TotalPages>
            </a:key>
            <a:value xmlns:b="http://schemas.datacontract.org/2004/07/IntegratorSuite.DataContracts">
               <b:AccountActivity>
                  <b:AccountNumber>11111111</b:AccountNumber>
                  <b:AccountType>2</b:AccountType>
                  <b:ActivityDescription>7.75000%10/30-11/10    $1602</b:ActivityDescription>
                  <b:Amount>4.1200000000</b:Amount>
                  <b:CallPut_HasValue>false</b:CallPut_HasValue>
                  <b:CallPut_Value>ALL</b:CallPut_Value>
                  <b:CmpQualCode i:nil="true"/>
                  <b:Currency>USD</b:Currency>
                  <b:Cusip></b:Cusip>
                  <b:Description1/>
                  <b:Description2/>
                  <b:EntryType>DC</b:EntryType>
                  <b:ExpirationDate>9999-12-31T23:59:59.9999999</b:ExpirationDate>
                  <b:JournalDescription i:nil="true"/>
                  <b:NetAmount>-4.1200000000</b:NetAmount>
                  <b:Price>0.000000</b:Price>
                  <b:PrincipalAmount>-4.1200000000</b:PrincipalAmount>
                  <b:Quantity>0.000000</b:Quantity>
                  <b:RecordType>H</b:RecordType>
                  <b:RootSymbol i:nil="true"/>
                  <b:SecQualCode i:nil="true"/>
                  <b:SecurityDescription>Cash</b:SecurityDescription>
                  <b:SecurityGroupCategoryID>0</b:SecurityGroupCategoryID>
                  <b:SecurityGroupDescription i:nil="true"/>
                  <b:SecurityQuantityConversion>0</b:SecurityQuantityConversion>
                  <b:SecurityTypeCode i:nil="true"/>
                  <b:StockConversionFactor>0</b:StockConversionFactor>
                  <b:StrikePrice>0.0</b:StrikePrice>
                  <b:Symbol/>
                  <b:SymbolCusip i:nil="true"/>
                  <b:TableID i:nil="true"/>
                  <b:TradeDate_HasValue>true</b:TradeDate_HasValue>
                  <b:TradeDate_Value>2010-11-11T00:00:00</b:TradeDate_Value>
                  <b:TradeDetailID_HasValue>false</b:TradeDetailID_HasValue>
                  <b:TradeDetailID_Value>0</b:TradeDetailID_Value>
                  <b:TradeNumber i:nil="true"/>
                  <b:TransactionType>Interest Collected</b:TransactionType>
                  <b:UnderlyingCusip i:nil="true"/>
                  <b:UnderlyingSymbol i:nil="true"/>
               </b:AccountActivity>
               <b:AccountActivity>
               ...

It appears that the forward slash in the node value is what is causing the match to fail. If I remove those from the xml and xpath query i get a match. Is there some issue with matching slashes in node values? Seem like a fundamental question but I can't find an answer.


Solution

  • It turns out that the problem was in the xml document below (way below) the portion I posted (as Alejandro suggested). The namespace URI for the element being queried was being redefined to a different URI later in the document. Once the second namespace was changed to a different unique name the xpath works as expected. For some reason redefining the URI later in the document caused the abnormal behavior in some xpath tools and not others when field data above the desired node had a slash in it. Thanks for everyones input. Next time I will post the entire document :).