I'm having trouble referencing a specific item in our order XML feed. I want to reference a specific "attribute-id", not the entire rowset.

XML reference:

        <custom-attribute attribute-id="recipientName">JeremyTest</custom-attribute>
        <custom-attribute attribute-id="senderName">Jeremy</custom-attribute>

My current code:

Set @giftMessageToFrom = BuildRowsetFromXML(@xml,'//shipment/custom-attributes/custom-attribute',1)

I would like to be able to check if it is a "recipientName" or "senderName" as sometimes customers will only put one or the other, not both.

Please also link to any documentation on this. I can't find anything specific to id's like this in XMLs. I've tried going the "Field" route to no avail along with trying to put the entire thing into the BuildRowsetFromXML but that also didn't work.


1 Answer 1


The online documentation for the BuildRowSetFromXML function isn't very clear on how to reference attribute values, but if you pay attention to the table at the bottom of the page, you'll notice that the column headers mirror the attribute names, but with the string "_att" appended to each (i.e., attribute-id_att is what you'll want to use).

With that, using your XML snippet above, the following code:

var @anonymousNode,

set @xmlPartial = 
   <custom-attribute attribute-id="recipientName">JeremyTest</custom-attribute>
   <custom-attribute attribute-id="senderName">Jeremy</custom-attribute>

set @anonymousNode = Concat('<root>', @xmlPartial, '</root>')
set @rowset = BuildRowsetFromXml(@anonymousNode, '//custom-attributes/custom-attribute', 1)
set @rowCount = RowCount(@rowset)

if (@rowCount > 0) then
  set @attrSuffix = '_att'

  for @i = 1 to @rowCount do
    set @row = Row(@rowset, @i)
    set @custAttr = Field(@row, 'Value')
    set @attrId = Field(@row, Concat('attribute-id', @attrSuffix))

    if (@attrId == 'recipientName') then
      Output(Concat(@custAttr, ' selected "recipientName"<br>'))
    elseif (@attrId == 'senderName') then
      Output(Concat(@custAttr, ' selected "senderName"<br>'))
      Output(Concat(@custAttr, ' did not make a selection<br>'))

  next @i

  Output(Concat('Content unavailable'))

Produces the following output:

JeremyTest selected "recipientName"
Jeremy selected "senderName"
  • 1
    This worked great. Thanks! Commented Mar 18, 2019 at 18:16

You must log in to answer this question.

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