1

I'm attempting to loop through an XML block and return the node names in addition to the values. Anyone know if that's possible?

%%[
  var @xml, @lineitems
  set @xml = "<order_items><item><sku>SKU1</sku></item><item><sku>SKU2</sku></item></order_items>"
  set @lineitems = BuildRowsetFromXML(@xml,"/order_items/item/*",0)

  set @rowCount = rowcount(@lineitems)

  for @i = 1 to @rowcount do
    set @lineitem = Row(@lineitems,@i)

    /* set @name = Field(@lineitem,"Name") */ /* this doesn't work */
    set @value = Field(@lineitem,"Value")
    outputline(concat("<br>name: ",@name, ", value: ",@value))

  next @i

]%%

Desired Output:

name: SKU, value: SKU1 
name: SKU, value: SKU2

The documentation on the BuildRowSetFromXML() function only includes Name, XML and *_att as retrievable columns in the result-set using the Field() function, which probably means I'm out of luck.

0

About the only way I can think to accomplish this is to have your first row mimic your column header names and just call that each time you need the column name. It is not exactly an elegant solution, but I do not believe there is one via AMPscript.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.