AnsweredAssumed Answered

Dealing with ValueMaps

Question asked by JamesM88 on Feb 19, 2013
Latest reply on Feb 26, 2013 by JamesM88
This is my first post on this community so apologies if its in the wrong place or has been answered in the past.

I have a problem with a XML string called 'local MailBody' that I need to parse in a PA process . It looks like this…
<change_asset_ownership>
<new_assets>
<asset>
<asset_id>pc1</asset_id>
<asset_sn>66519001</asset_sn>
</asset>
<asset>
<asset_id>pc2</asset_id>
<asset_sn>66520002</asset_sn>
</asset>
</new_assets>
</change_asset_ownership>

To parse the string I use the following statement to build a valuemap object.

Process.new_assets = convertXml(applyXPath(localMailBody,"//change_asset_ownership/new_assets/asset"));

Its fine when there’s two or more asset nodes in the string but I get in to trouble when there’s only one asset node.

When there’s two or more nodes I create a value map object that looks like…

Process.new_assets
.asset[]
.asset_sn
.asset_id


When there’s one asset node I get an object like this…..

Process.new_assets
.asset_sn
.asset_id

Does anyone have advice on a better approach to parsing this data, one that creates a consistent structured object?

Outcomes