Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Changing a value of an xml field after extracting from request

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

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    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.

  • smukher
    smukher Posts: 8
    edited July 2019

    The request is not getting posted

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Could you attach the sample xml as a file?

  • smukher
    smukher Posts: 8

    PFA

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    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

  • smukher
    smukher Posts: 8
    edited July 2019

    It worked. Thanks William

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Glad it worked :smile:

  • smukher
    smukher Posts: 8

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

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

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

  • smukher
    smukher 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) "

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    What version of the product are you using?

  • smukher
    smukher Posts: 8

    9.10

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

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

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    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