Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Help Looping through XML File

angelschneider
5 - Atom

Hi everyone. I am a new Alteryx user and would appreciate some assistance in solving an issue I'm having with creating a loop for parsing a xml file. For simplicity, let's start with a single field that I'll call InfoGrp. Here's what I'm doing:

 

  • Selecting InfoGrp_OuterXML
  • Parsing Root element of InfoGrp_OuterXML
  • Selecting Data A, B & C from the results

This all runs fine, but here's where I run into my issue. I don't just have one InfoGrp field; I have several (e.g., InfoGrp, InfoGrp_2, InfoGrp_3, etc.), the number of which could change, depending on my source file. I was able to figure out a way to count the number of InfoGrp fields, but here's where I get stuck. If I was programming this, for example, I'd create a loop with 2 variables: one for the count, which would decrease each time I ran my loop, and one for the selection name, which would increase with every loop (i.e., 'InfoGrp_' + variable + '_OuterXML'). Unfortunately, I have no idea how to do this in Alteryx. My thanks to anyone who can provide me with some guidance.

5 REPLIES 5
danilang
19 - Altair
19 - Altair

Hi @angelschneider 

 

Can you provide a sample input file.  With this we should be able to provide you with a relatively simple workflow.

 

Thanks

 

Dan 

angelschneider
5 - Atom

Here's a sample xml file similar in structure to what I'm dealing with. Thanks, again, for your help.

 

 

angelschneider
5 - Atom

Any luck with this file? Please let me know if you have questions.

danilang
19 - Altair
19 - Altair

Hi @angelschneider 

 

Parsing XML is tricky with Alteryx.  There is no simple way to tell Alteryx to give you a tree based on an arbitrary XML file.   I find that the best way is to parse your file is level by level, pulling out either the child values and/or the outer_xml depending on what you need from each level.   

 

WF.png

 

This work flow parses each level in turn and builds out the data contained within each node.  The 2 outputs return either the data by columns or by rows as shown below

 

Data in columnsData in columnsData in rowsData in rows

 

Note that when your dealing with XML, you data set can balloon very quickly.  This is because the outer_xml of all the higher level elements is included in each row, so if your initial XML file is 2MB is size, you have a 2MB string in each row of your output.  The way to deal with this is to use Select tools between the XML Parse tools to remove the outer_xml for levels that you've already processed.

 

Dan

angelschneider
5 - Atom

Brilliant! I see where I was going wrong now and need to revisit my understanding/use of returning Child Values. Thank you so much!

Labels