Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Problem with E4X and element names with periods

  1. #1
    Join Date
    Jun 2009
    Posts
    23

    Default Problem with E4X and element names with periods

    Hi I'm need to build XML documents using Kettle and E4X however I've encountered a problem because some of the element names have periods.

    e.g.
    var xmlDoc=
    <root>
    <elem.1>blah</elem.1>
    </root>

    xmlDoc.root.elem.1=foo; // invalid cause of the dot

    According to the E4X spec, I should be able to do

    xmlDoc["elem.1"] = "foo";

    but that doesn't work. Any ideas or suggestions?

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    If I try this on 3.2.0GA:

    Code:
    var xml = <root><elem.1>foo</elem.1></root>
    
    xml["elem.1"] = "bar";
    
    var xmlString2 = xml.toXMLString();
    then I'm seeing the element set to "bar", just as it should.

    What exactly is the problem?

  3. #3
    Join Date
    Jun 2009
    Posts
    23

    Default

    Hi Matt,
    thanks for the quick response.

    My example wasn't quite right but with your info I was able to get it working (kind of).


    However, I noticed another odd problem (maybe you have a quick solution for that too).

    If I do this:

    // begin ---
    var xml = <root><parent><child><elem.1>foo</elem.1></child></parent></root>;

    var xml1 = xml["elem.1"];
    xml1 = "bar";

    xml..child.appendChild(<elem.2>faa</elem.2>);

    var xmlString2 = xml.toXMLString();

    //var xml2 = xml["elem.1"];
    //xml2.appendChild(<another_child_elem>boo</another_child_elem>);
    // end ---
    It's fine

    But if I uncomment the lines and do this:

    // begin ---
    var xml = <root><parent><child><elem.1>foo</elem.1></child></parent></root>;

    var xml1 = xml["elem.1"];
    xml1 = "bar";

    xml..child.appendChild(<elem.2>faa</elem.2>);

    var xmlString2 = xml.toXMLString();

    var xml2 = xml["elem.1"];
    xml2.appendChild(<another_child_elem>boo</another_child_elem>);
    // end ---

    if fails with

    2009/07/03 13:27:17 - Modified Java Script Value.0 - ERROR (version 3.2.0-GA, build 10572 from 2009-05-12 08.45.26 by buildguy) : Unexpected error :
    2009/07/03 13:27:17 - Modified Java Script Value.0 - ERROR (version 3.2.0-GA, build 10572 from 2009-05-12 08.45.26 by buildguy) : org.pentaho.di.core.exception.KettleValueException:
    2009/07/03 13:27:17 - Modified Java Script Value.0 - ERROR (version 3.2.0-GA, build 10572 from 2009-05-12 08.45.26 by buildguy) : Javascript error:
    2009/07/03 13:27:17 - Modified Java Script Value.0 - ERROR (version 3.2.0-GA, build 10572 from 2009-05-12 08.45.26 by buildguy) : TypeError: appendChild is not a function, it is xml. (script#12)

    Any ideas (I need to use the appendChild).

    -- update --

    or even (tries to append to same element ('child'))

    // begin ---
    var xml = <root><parent><child><elem.1>foo</elem.1></child></parent></root>;

    var xml1 = xml["elem.1"];
    xml1 = "bar";

    xml..child.appendChild(<elem.2>faa</elem.2>);

    var xmlString2 = xml.toXMLString();


    var xml2 = xml["child"];
    xml2.appendChild(<another_child_elem>boo</another_child_elem>);
    // end ---
    Last edited by michelb; 07-03-2009 at 01:36 PM.

  4. #4
    Join Date
    Jun 2009
    Posts
    23

    Default

    Never mind. I figured out my problem; for some reason, I thought that with this:

    var xml1 = xml["elem.1"];
    xml1 = "bar";

    xml1 would be a reference to xml at elem.1, not a copy ...

    -- update

    I think I need to review my code to make sure my variables are used correctly because this example does work:

    var xml = <root><elem.1><child>foo</child></elem.1></root>
    var xml_elem = xml["elem.1"];
    xml_elem.appendChild = <baby>bar</baby>;

    (i.e. xml_elem is a ref to xml and does add the child as expected ...)
    Last edited by michelb; 07-03-2009 at 01:55 PM.

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.