вторник, 20 ноября 2018 г.

How to decode XML string Ax 2012

Hi again! I haven't written posts recently. But today I had a task, which was unusual for me - decode XML string to readable view to parse particular value. Or decoding the XML string.
So, I got a xml node like this

<column columnName="OrderLineFieldValues">&lt;OrderLineFieldValueCollection&gt;&lt;OrderLineFieldValue&gt;&lt;OrderLineFieldSystemName&gt;Backordered&lt;/OrderLineFieldSystemName&gt;&lt;Value&gt;4&lt;/Value&gt;&lt;/OrderLineFieldValue&gt;&lt;OrderLineFieldValue&gt;&lt;OrderLineFieldSystemName&gt;CutInspect&lt;/OrderLineFieldSystemName&gt;&lt;Value&gt;&lt;/Value&gt;&lt;/OrderLineFieldValue&gt;&lt;OrderLineFieldValue&gt;&lt;OrderLineFieldSystemName&gt;Mileage&lt;/OrderLineFieldSystemName&gt;&lt;Value&gt;&lt;/Value&gt;&lt;/OrderLineFieldValue&gt;&lt;OrderLineFieldValue&gt;&lt;OrderLineFieldSystemName&gt;Notes&lt;/OrderLineFieldSystemName&gt;&lt;Value&gt;&lt;/Value&gt;&lt;/OrderLineFieldValue&gt;&lt;OrderLineFieldValue&gt;&lt;OrderLineFieldSystemName&gt;SerialNumber&lt;/OrderLineFieldSystemName&gt;&lt;Value&gt;&lt;/Value&gt;&lt;/OrderLineFieldValue&gt;&lt;/OrderLineFieldValueCollection&gt;</column>';

So, looks a little bit confused, doesn't it?

Well, from this mess I'd need to get particular values. How can I do this?  First of all, I started searching some sort of open API to do this but faced with lack of it. But after 1 hour or so I finally found the desired solution. For me it looks like this:
static void Job3(Args _args)
{
    str output;
    str input = @'my encoded XML string';
 
    output = System.Web.HttpUtility::HtmlDecode(input);
 
    info(output);
}

All that I need is in one HtmlDecode method! It's nice. Now I can continue working on the parser which could help me to get the required value from the XML node.

Hope, this piece of code would be useful for someone other as it was for me!

Happy DAXing!