Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Issue parsing XML file that is a saved as TXT

Wafarian
8 - Asteroid

Hi,

 

I am unable to parse XML file that we received from a server. the file is saved as XXX.xml.txt

 

below is my workflow, config settings and errors.

 

 

 

12 REPLIES 12
DataNath
17 - Castor
17 - Castor

Hey @Wafarian, have you tried reading it in as an XML?

 

 

DataNath_0-1683273966735.png

Wafarian
8 - Asteroid

Hi,

 

the file is saved as TXT but has an XML structure.

 

 

DataNath
17 - Castor
17 - Castor

Hey @Wafarian, if you pull on an Input Data tool and then choose your file, you can still just select to read it in as an XML from the dropdown, even though it's a .txt - see here:

 

DataNath_0-1683279161676.png

Wafarian
8 - Asteroid

Hi,

 

Getting error "Error: XML Parse (2): invalid document structure at Line:3 and Column:7 at value"


 

Thanks,

 

 

DataNath
17 - Castor
17 - Castor

@Wafarian I'm not too experienced working with XML but because of the nesting I think you may need to do an initial parse of your field for the <Item> tag - you can search for a specific child by using this configuration like so:

 

DataNath_1-1683280880708.png

 

The resulting fields of that should then have the <Amount> data, that you can use a second XML Parse tool to go over. In this example the <Fields> data that's nested within the configuration would be what I'd parse in my second tool:

 

DataNath_2-1683280926649.png

DataNath_3-1683280966531.png

danilang
19 - Altair
19 - Altair

Hi @Wafarian 

 

Can you attach the actual xml file, as opposed to an image of it?  The error messages suggest that the file is badly structured, but it looks correct in the image. 

 

Thanks

 

Dan

apathetichell
19 - Altair

Just chiming in to support @danilang 's suggestion - I don't even see a line 3 in the screengrab....

Wafarian
8 - Asteroid

Hi,

 

I am not able to attached the file due to file extension .XML.TXT

 

However, below is the sample file

 

____________________________________________________________________________

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<AmountList>
<Envelope>
<Version>1.0</Version>
<SenderID>777</SenderID>
<ReceiverID>666</ReceiverID>
<TransactionID>4444</TransactionID>
</Envelope>
<Head>
<CurrencyCode>ZAM</CurrencyCode>
<Date>2023-05-05</Date>
<ValidityAreas>
<ValidityArea>AREA</ValidityArea>
</ValidityAreas>
</Head>
<Items>
<Item>
<MatID>FFFF</MatID>
<Code>11551</Code>
<Description>Soya</Description>
<Amount>
<Price>
<ValidFrom>2023-05-05</ValidFrom>
<ValidTo>9999-12-31</ValidTo>
<Price>50.00</Price>
</Price>
</Amount>
</Item>
<Item>
<MatID>XXXX</MatID>
<Code>111</Code>
<Description>Milk</Description>
<Amount>
<Price>
<ValidFrom>2023-05-05</ValidFrom>
<ValidTo>9999-12-31</ValidTo>
<Price>10.00</Price>
</Price>
</Amount>
</Item>
</Items>
</AmountList>

Wafarian
8 - Asteroid

Hi,

 

the file is an xml file but the extension is TXT and that is how we receive it from the business. It is the TXT extension that is causing the problem.

 

What I actually need from the file is this section 

 

<Items>
    <Item>
      <MatID>FFFF</MatID>
      <Code>11551</Code>
      <Description>Soya</Description>
      <Amount>
        <Price>
          <ValidFrom>2023-05-05</ValidFrom>
          <ValidTo>9999-12-31</ValidTo>
          <Price>50.00</Price>
        </Price>
      </Amount>
    </Item>
    <Item>
      <MatID>XXXX</MatID>
      <Code>111</Code>
      <Description>Milk</Description>
      <Amount>
        <Price>
          <ValidFrom>2023-05-05</ValidFrom>
          <ValidTo>9999-12-31</ValidTo>
          <Price>10.00</Price>
        </Price>
      </Amount>
    </Item>
  </Items>

I only need the data from the  <Items>     </Items>  section

Labels
Top Solution Authors