Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: read data from xml file

  1. #1

    Default read data from xml file

    Hi All,
    I am having a product xml file, where data is at product level. Every product is associated with one or more than one category.

    Product.xml file:-

    +++++++++++++++++++++++++++++++++
    <Products>
    <Product Id="1234" Name="Dell Laptop" New="1" Discount="1" OS="Windows7">
    <Supplier ASI="2323" Name="JK Corp" />
    <UniqueId>673563</UniqueId>
    <Number>22-38372673</Number>
    <Description>Dell Laptop. Windows7 OS</Description>
    <Categories>
    <Category Name="Dell" />
    <Category Name="Computers" />
    <Category Name="Laptop" />
    </Categories>
    </Product>
    <Product Id="1235" Name="Microsoft Office 2010" New="1" Discount="1" OS="Windows7">
    <Supplier ASI="2323" Name="JK Corp" />
    <UniqueId>673563</UniqueId>
    <Number>22-38372673</Number>
    <Description>Microsot Office 2010</Description>
    <Categories>
    <Category Name="Microsoft" />
    <Category Name="Software" />
    </Categories>
    </Product>
    </Products>
    +++++++++++++++++++++++++++++++++

    Now based on number of categories, I have to create distinct row in mysql table.
    Output data should be:-
    product_id, Name, Category
    1234, Dell Laptop, Dell
    1234, Dell Laptop, Computers
    1234, Dell Laptop, Laptop
    1235, Microsoft Office 2010, Microsoft
    1235, Microsoft Office 2010, Software

    I am using following logic to read record in "Get MXL Data" step :-
    Xpath - /Products/Product
    Product_Id = @Id
    Name = @Name
    Category = Categories/Category/@Name
    This is not working properly and I am getting only one record per product from xml.

    Any thought on how to acheive this logic in PDI 4.1.0?

    Regards,
    Ritesh
    Attached Files Attached Files

  2. #2

    Default

    Hi Ritesh,

    Follow this...
    Xpath - /Products/Product/Categories/Category
    Product_Id = ../../@Id
    Name = ../../@Name
    Category = @Name
    This will give you result that you desire.

    Regards,
    ~Kasim

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.