Changing a value of an xml field after extracting from request

smukhersmukher Posts: 8

I am trying to extract the "ns1: month" field from the following request using XML Databank and then increase the value by 3 and populate it in response.

<?xml version="1.0" encoding="UTF-8"?>






CallingAppCode
VLM0



RZZCA82

26
06
2019

Q



.

Please suggest a solution for this.

Comments

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    Hi,
    The example you posted doesn't look like xml, maybe it got garbled when the post was submitted. The data bank tool will help you generate the xpath to select the particular xml element you want, then you can manually edit the selection xpath and can add math functions to do the addition.

  • smukhersmukher Posts: 8
    edited July 17

    The request is not getting posted

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    Could you attach the sample xml as a file?

  • smukhersmukher Posts: 8

    PFA

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    Using the xml data bank I input the xml and from the tree view I clicked the month element. Then I edited the xpath to add " + 1" to the end. Here is the final xpath will return the value 7 for the sample provided.

    /:Envelope/:Body[1]/:GetNextNextPaymentDateRequest[1]/:getNextNextPaymentDateReq[1]/:nextPayDate[1]/:month[1]/text() + 1

  • smukhersmukher Posts: 8
    edited July 18

    It worked. Thanks William

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    Glad it worked :smile:

  • smukhersmukher Posts: 8

    It is not handling when month equals to 10 because it will throw 13 as the month value.

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    I am guessing you mean that when the month is 12 then the data bank returns 13. Here is an xpath that uses max and mod to keep the values within the values 1-12

    max ((1, (/:Envelope/:Body[1]/:GetNextNextPaymentDateRequest[1]/:getNextNextPaymentDateReq[1]/:nextPayDate[1]/:month[1]/text() + 1) mod 13))

  • smukhersmukher Posts: 8

    Getting this error: Problem evaluating XPath expression. Error message = "net.sf.saxon.trans.XPathException: A sequence of more than one item is not allowed as the first operand of 'mod' (1, 9) "

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    What version of the product are you using?

  • smukhersmukher Posts: 8

    9.10

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    What service pack version? I tested the xpath with 9.10.6 and it worked.

  • williammccuskerwilliammccusker Posts: 227 ✭✭

    Hi,
    I missed that you wanted to increment by 3 months. This should work for that case, its some funny math but it works for values 9, 10, 11 and 12 where as the previous solutions did not.

    Does this work for you?

    (/:Envelope/:Body[1]/:GetNextNextPaymentDateRequest[1]/:getNextNextPaymentDateReq[1]/:nextPayDate[1]/:month[1]/text() -1 + 3) mod 12 + 1

Sign In or Register to comment.