0

I need to modify my XML in SQL Server 2016 to add a Namespace and a couple of header tags. Currently I have a Select Query That gives me this block

Select @MAXML, @TRANSXML,@HOSTSETTINGSXML FOR XML PATH

  <merchantAuthentication>
  <name>myName</name>
  <transactionKey>myKey</transactionKey>
 </merchantAuthentication>
      <transactionRequest>
    <amount>5.500000000000000e+000</amount>
  </transactionRequest>
  <hostedPaymentSettings>
    <settingName>hostedPaymentBillingAddressOptions</settingName>
    <settingValue>{"show": true, "required":true}</settingValue>
  </hostedPaymentSettings>
  <hostedPaymentSettings>
    <settingName>hostedPaymentButtonOptions</settingName>
    <settingValue>{"text": "Pay"}</settingValue>
  </hostedPaymentSettings>
  <hostedPaymentSettings>
    <settingName>hostedPaymentReturnOptions</settingName>
    <settingValue>anyValue</settingValue>
  </hostedPaymentSettings>  

And this should be my output:

<Request>
    <Body>
        <Xml>
            <getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
                 My xml from above
        </getHostedPaymentPageRequest>
    </Xml>
</Body>
</Request>

I am stuck. tried a number of times but could not get the exact xml. Thanks is advance.

1 Answer 1

1

I will give my own answer, it might be helpful to others. Step1: Convert entire XML to string and add headers as string Step2: Convert the new string back to XML

Step1:

Set @strXML = '<Request><Body><Xml><getHostedPaymentPageRequest 
xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">'+
                Convert(nvarchar(MAX),@x)+
                 '</getHostedPaymentPageRequest></Xml></Body></Request>'

Step2:

SET @RequestXML = (SELECT CONVERT(XML,(SELECT CAST(@strXML AS XML))))
Sign up to request clarification or add additional context in comments.

Comments

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.