Hitachi Vantara Pentaho Community Forums
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to XML

  1. #1
    abayona Guest

    Default How to XML

    Hi All,

    I have this table data:

    month,net_revenue
    jan,15500
    feb,1200
    0

    and I want do this XML:

    <graph ...>
    < set name = 'jan' value='15500' />
    < set name = 'feb' value='12000' />
    </graph>

    How I do this?

    Thanks!

  2. #2

    Talking

    I can give you some tips:

    1.Use step Split Fields and put ',' as delimeter parameter
    2.Use step 'Add Constant' to add string
    3. Use step Calculator Step to concat columns
    4. Use Text output file to write to file.
    Alternatively use "Select Values" to choose only column you want.


  3. #3
    Join Date
    May 2006
    Posts
    4,882

    Default

    Attributes are not yet in XML Output step (http://jira.pentaho.com/browse/PDI-2147).

    For 1 "set name" line you can use XML Add step, which will generate the line you want in an extra field.

    After that you can remove the original fields, and add the beginning/ending graph lines with an add constant step and using an append step to get the lines in the right order... followed by a text file output step.

    Regards,
    Sven

  4. #4

    Default

    Hi,

    You can try the attached example.
    In that one i have used "Processing XML with E4X" concept.
    PDI 3.1 supports this feature.

    Please let me know any issues after testing.

    Thanks,
    Attached Files Attached Files

  5. #5
    DEinspanjer Guest

    Default

    Quote Originally Posted by pplvinay View Post
    Hi,

    You can try the attached example.
    In that one i have used "Processing XML with E4X" concept.
    PDI 3.1 supports this feature.

    Please let me know any issues after testing.

    Thanks,
    Yay! I'm happy to see someone getting use out of the E4X support. Thanks for providing that sample!

  6. #6
    abayona Guest

    Default

    Thank you! It's so good!

  7. #7
    Join Date
    May 2006
    Posts
    4,882

    Default

    Funny... I don't see the E4X

  8. #8
    DEinspanjer Guest

    Default

    Quote Originally Posted by sboden View Post
    Funny... I don't see the E4X
    Hah.. Yeah, that's what I get for just seeing the statement that they used E4X and not opening the transformation and looking at it.

    Technically, they are sorta using E4X because of that last line where they say:
    var a = new XML(total);
    but it isn't really doing anything for them. They could have just as easily said:
    var a = total;
    and gotten the exact same output. ::shrug::

    Anyway.. Here is my example that actually does make use of E4X to interpolate the variables into the XML document.
    Attached Files Attached Files

  9. #9
    Join Date
    Jun 2009
    Posts
    23

    Default

    Please correct me if I'm wrong but isn't there a step missing from these samples? Don't you need to add a 'Text Output' step to actually read your 'a' and output the result to an xml file (I added it in the attachments).

    Also this doesn't quite do what the OP asked for; from what I can tell, this will produce something like (not even valid XML):

    <graph>
    <set name="jan" value="15500"/>
    </graph>
    <graph>
    <set name="feb" value="12000"/>
    </graph>


    not

    <graph>
    <set name="jan" value="15500"/>
    <set name="feb" value="12000"/>
    </graph>

    Note that this would work if you want to have the result in different files (set the 'split every ... row' to 1 instead of 0 on the 'text output' settings):

    e.g. file0001.xml

    <graph>
    <set name="jan" value="15500"/>
    </graph>

    file0002.xml
    <graph>
    <set name="feb" value="12000"/>
    </graph>


    Please correct me if I'm wrong (I'm a newbie trying to learn this stuff). Also, how would you modify it to get all the rows within the same <graph> tag?
    Attached Files Attached Files
    Last edited by michelb; 06-04-2009 at 09:23 AM.

  10. #10
    DEinspanjer Guest

    Default

    Quote Originally Posted by michelb View Post
    Please correct me if I'm wrong but isn't there a step missing from these samples? Don't you need to add a 'Text Output' step to actually read your 'a' and output the result to an xml file (I added it in the attachments).
    Yes, you do need to land the XML string somewhere. That is left as an exercise for the reader since there are many different ways they might want to land the data.

    Quote Originally Posted by michelb View Post
    Also this doesn't quite do what the OP asked for; from what I can tell, this will produce something like (not even valid XML):
    ...
    Please correct me if I'm wrong (I'm a newbie trying to learn this stuff). Also, how would you modify it to get all the rows within the same <graph> tag?
    Quite right and good catch! My example was not carefully tested enough it seems.

    To get the <set> elements all under one <graph> root, you'll need to use the XML Join step. I've attached a new example that demonstrates that.
    Attached Files Attached Files

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.