Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: XML file to csv

  1. #1

    Default XML file to csv

    Hello everyone,

    I am struggling with a small but tricky xml-to-csv conversion.

    Input file:-
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <products>
        <product product-id="1">
            <name>laptop</name>
            <custom-attributes>
                <custom-attribute id="a">true</custom-attribute>
                <custom-attribute id="b">false</custom-attribute>
                <custom-attribute id="c">
                    <value>large</value>
                    <value>medium</value>
                    <value>small</value>
                </custom-attribute>
                <custom-attribute id="d">false</custom-attribute>
            </custom-attributes>
        </product>
    </products>
    Output file:-
    Code:
    product-id, name, custome-attribute, custome-attribute-id, value
    1, laptop, true, a, (null)
    1, laptop, false, b, (null)
    1, laptop, (null), c, large
    1, laptop, (null), c, medium
    1, laptop, (null), c, small
    1, laptop, false, d, (null)
    Here you can see that :-
    1. custom-attribute is multi occurrence element
    2. If custom-attribute is having child element 'value', in that case there is no separate value for custom-attribute.
    3. 'value' is multi occurrence element as well.
    4. in example output which I have mentioned, '(null)' represents null value.

    I did lots of play around in 'Get data from XML'. Looks like I am not able to select correct loop or might be some wrong XPath. Please look at it.

    Any help, any hint will be much appreciated.

    PDI - 5.4.0 / Windows 10

    Regards,
    Ritesh

  2. #2
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    I wonder what you tried to fail.

    The golden rule is to set the loop to the innermost repeating element of interest.
    Would be //value but it's missing sometimes and you must cope with mixed content, so choose custom-attribute instead.
    Now deal with the mixed content by chaining a second GDFX step and you're done.
    Attached Files Attached Files
    So long, and thanks for all the fish.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.