Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Parse XML with optional field

Cyprien
6 - Meteoroid

Hi All,

 

I'm trying to parse an xml with optional field so I've build my flow alteryx extensively to take all the field into consideration but when I have an xml with not all the field the flow fail because it cannot find the field.

 

IE I have the following xml :

<field1>

<filed2> (optional)

So my flow is Parsing the xml to have the 2 field -> Condition !isnull[field2] -> ....

So for a xml with both field it's working, but for an xml with only field1 I get an error on the condition and my flow is failing.

 

Do you have any idea on how I can create a flow which is working for both xml?

 

Thanks

Cyprien

5 REPLIES 5
KaneG
Alteryx Alumni (Retired)

Hi @Cyprien,

 

There is ways using Macros and detours etc, however the easiest way around this is to transpose the data so that both fields appear in the one field. You can then just parse that field and crosstab back if needed.

 

Kane

Cyprien
6 - Meteoroid

Hi @KaneG,

 

Thanks for your answer, but I don't think the transposition will fit my problem as I can have thousands of records being treated in my flow. I think it will be easier for me to use Macro as I will have to do it for several flow, with very complex XML.

Do you have any example on how to do it with macros and detour?

 

Thanks

Cyprien

KaneG
Alteryx Alumni (Retired)
I don't have an example. I advise trying the transpose, but if not then there is a couple of possible methods,

You can insert a dummy row with both fields and then use a filter to s split the records 2 ways depending on whether that field is null.

You can have the processing inside a batch macro, where the batch is dependent on that field being populated and a detour is triggered based on whether the field is populated (decided in the outside workflow).

I have packed up for the week, but, If you have some sample data, then I might be able to whack something up on the weekend if no one else has an example.
AdamR_AYX
Alteryx Alumni (Retired)

Check out the "Ensure Fields" macro in the CReW macro pack

 

http://www.chaosreignswithin.com/p/macros.html

 

Just add it after your XML parse tool and put in the field names that you need the data stream to always have.

Adam Riley
https://www.linkedin.com/in/adriley/
Cyprien
6 - Meteoroid

Hi @AdamR,

 

Thanks a lot this is exactly what I was looking for :)

 

Cyprien

Labels