Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Unable to view all child elements in xml

  1. #1

    Default Unable to view all child elements in xml

    Hello!
    I have an xml structure with multiple "department" elements and each of them having multiple "employee" elements. When I use the option 'Get data from XML' and use Xpath for looping as "//department/", I get just the first employee element of each department along with department details.
    For eg:
    <dept> <name>ADMINISTRATION</name>
    <employee>
    <Fname>ANANT</Fname>
    <Lname>MURTHY</Lname>
    </employee>
    <employee>
    <Fname>DEAN</Fname>
    <Lname>JONES</Lname>
    </employee>
    </dept>
    In this, I just get the first element i.e. employee corresponding to "ANANT MURTHY" and not the rest
    How can I view all the employee elements of each department ALONG WITH (PARENT) DEPARTMENT DETAILS?
    (PS-I am attaching the xml input file.)
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    What do you get if you change the loop path to "/BODY/department/employee" ?

  3. #3

    Default

    Yeah, that does give me all the employee details but then I don't get the department details correctly. Even when I give the xpath /BODY/department/name for a 'dname' field in the Fields tab, it just fetches the first department for all the employees, which is incorrect.

    I want both department(parent) as well as its corresponding employee(child) details which I am unable to achieve.
    Can you please help me with that?

  4. #4
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    As long as the data is structured as it is in your sample XML, you can loop on /BODY/department/employee and reference ../name and ../id for the department name and department id.

    Try it, and show us where you got to.

  5. #5

    Default

    I found the solution to the problem. The issue was with formulating the Xpath expression. I just had to mention ancestor::node() in the xpath to get the desired parent. Your solution worked too!
    Thanks a lot!!

  6. #6
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    When I built a trial of your sample data, I didn't need to use ancestor::node()
    That looks like code of some sort, which you don't really need to use to build transforms. If you are reaching into a code tool-box, sit back and think... There aren't a lot of places you need to use code.

  7. #7
    Join Date
    Aug 2011
    Posts
    360

    Default

    Quote Originally Posted by gutlez View Post
    When I built a trial of your sample data, I didn't need to use ancestor::node()
    That looks like code of some sort, which you don't really need to use to build transforms. If you are reaching into a code tool-box, sit back and think... There aren't a lot of places you need to use code.
    This is note "code", this is just XPATH......
    But your previous is right: the current node in the loop is enployee, so an xpath like ../name should be fine.
    This is the same as using ancestor:: which get you to the ancestor of the current node.

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.