0

Issue From the attached XML i am traying to read the value of "vertex_retail_delivery_fee" with below code.

<custom-attribute attribute-id="vertex_retail_delivery_fee">0.27</custom-attribute>
<custom-attribute attribute-id="vertex_retail_delivery_fee_deducted_from_total_tax">5.07</custom-attribute>
<custom-attribute attribute-id="vertex_taxation_details">

Goal is to display the value if the xml has the attribute else it should be display "0.00" the below logic is throwing me error.

An error occurred when attempting to evaluate a RowCount function call. See inner exception for details. xml parameter is invalid. Function: BuildRowsetFromXML(@XML, 'custom-attributes/custom-attribute[@attribute-id="vertex_retail_delivery_fee"]')

Code:

if rowcount(BuildRowsetFromXML(@XML, '/custom-attributes/custom-attribute[@attribute-id="vertex_retail_delivery_fee"]')) > 0 
then
set @RetailFee= Field(Row(BuildRowsetFromXML(@XML, '/custom-attributes/custom-attribute[@attribute-id="vertex_retail_delivery_fee"]',0),1), 'Value'),'

2 Answers 2

0

Used this and it worked:

%%[
  SET @xml = ATTRIBUTEVALUE('xml')
  SET @rs = BuildRowSetFromXML(@xml, '/order/custom-attributes/custom-attribute', 0)
  SET @rc = ROWCOUNT(@rs)
  IF ROWCOUNT(@rs) > 0 THEN
    FOR @i = 1 to @rc DO
      SET @nodepath = CONCAT("/order/custom-attributes/custom-attribute[", @i, "]/")
      SET @attr = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath, "@attribute-id"),0),1),'Value')
      IF @attr == "vertex_retail_delivery_fee" THEN
        SET @value = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath, "text()"),0),1),'Value')
      ENDIF
    NEXT
  ENDIF
]%%
<hr>
value ==== %%=v(@value)=%%
<hr>
1
  • This Worked and was really helpfull
    – syed Basha
    Jul 5, 2022 at 11:20
1

You'll have to find all the custom-attribute nodes, loop through each of them to fetch the attribute-id value and match it with 'vertex_retail_delivery_fee' and get its value to get the delivery fee value. Below is a sample code.

    %%[
      var @xml
      set @xml = ""
      set @xml = concat(@xml, '<custom-attributes>')
      set @xml = concat(@xml, ' <custom-attribute attribute-id="vertex_retail_delivery_fee">0.27</custom-attribute>')
      set @xml = concat(@xml, '    <custom-attribute attribute-id="vertex_retail_delivery_fee_deducted_from_total_tax">5.07</custom-attribute>')
      set @xml = concat(@xml, '    <custom-attribute attribute-id="vertex_taxation_details"/>')
      set @xml = concat(@xml, '</custom-attributes>')
      
      //OutputLine(concat('<br>XML value = ' , @xml))
    
      set @rowCount = rowcount(BuildRowsetFromXML(@xml, '/custom-attributes/custom-attribute'))
    
      //OutputLine(concat('<br>Number of custom-attribute rows = ' , @rowCount))
    
      if @rowCount > 0 then 
      for @i = 1 to @rowCount do
        set @nodePathAttributeId = concat('/custom-attributes/custom-attribute[',@i,']/@attribute-id')
        set @attributeId= Field(Row(BuildRowsetFromXML(@XML, @nodePathAttributeId,0),1), 'Value')
        //OutputLine(concat('<br>attributeId = ', @attributeId))
        if @attributeId == "vertex_retail_delivery_fee" then 
          //OutputLine(concat('<br>Found vertex_retail_delivery_fee'))
          set @nodePathForVal = concat('/custom-attributes/custom-attribute[',@i,']')
          set @val= Field(Row(BuildRowsetFromXML(@XML, @nodePathForVal,0),1), 'Value')
          OutputLine(concat('<br>vertex_retail_delivery_fee Value = ' ,@val))
        endif
       next @i
      endif
    
      
    ]%%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .