Hitachi Vantara Pentaho Community Forums
Results 1 to 9 of 9

Thread: XML Input bombing when getting an optional node, but not when getting a string

  1. #1
    Join Date
    Apr 2007
    Posts
    2,010

    Default XML Input bombing when getting an optional node, but not when getting a string

    Hi,

    Not sure if anyone has seen this, but we have an XML which has repeating values. So I wanted to get the XML for the whole node then loop on it in the next step.

    However; Whilst you can get the String value of a node in XML input, and if it isnt there it'll just return null correctly, if you try to do that for the entire node then PDI Crashes.

    (Not got the exception to hand but it's a pretty obscure one!)

    Should that work? Has anyone seen this before?

    Thanks,
    Dan

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

    Default

    Didn't see it yet, but could easily make it happen on my machine.

    Here's my insight:

    Method GetXMLData.processPutRow() has two lines of code calling a method on a null object.
    The bold lines contain the necessary changes to make this bug go away.
    Additionally, class Node requires import of org.dom4j.Node.
    If you open a jira case, add a link here, please.
    If you don't, just say so, and I will.

    Code:
                    // Handle namespaces
                    if(meta.isNamespaceAware())
                    {
                        XPath xpathField = node.createXPath(addNSPrefix(XPathValue, data.PathValue));
                        xpathField.setNamespaceURIs(data.NAMESPACE);
                        if(xmlDataField.getResultType()== GetXMLDataField.RESULT_TYPE_VALUE_OF)
                            nodevalue=xpathField.valueOf(node);
                        else { 
                            Node tempnode = xpathField.selectSingleNode(node);
                            nodevalue = tempnode == null ? "" : tempnode.asXML();
                        }
                    } else
                    {
                        if(xmlDataField.getResultType()== GetXMLDataField.RESULT_TYPE_VALUE_OF)
                            nodevalue=node.valueOf(XPathValue);
                        else {
                            Node tempnode = node.selectSingleNode(XPathValue); 
                            nodevalue = tempnode == null ? "" : tempnode.asXML();
                        }
                    }
    So long, and thanks for all the fish.

  3. #3
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    excellent thanks! I've raised it here: http://jira.pentaho.com/browse/PDI-10380

  4. #4
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    Support are asking for samples - I tried a very simple example and annoyingly it worked, not sure why that is. PDI version perhaps.
    If you could attach your example to the jira that would rock! Thanks!

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

    Default

    Sorry, I'm not allowed to create attachments to Jira issues I don't own.
    Attached Files Attached Files
    So long, and thanks for all the fish.

  6. #6
    Join Date
    Nov 1999
    Posts
    459

    Default

    Looks like the zip does only contain a ktr not the XML... could you double check?

    Thanks Marabu!

    I'll attach it then to the case.

    Cheers,
    Jens

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

    Default

    Hi Jens, the transformation serves as XML input.
    So long, and thanks for all the fish.

  8. #8
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    lol genius. I like it.

  9. #9
    Join Date
    Sep 2010
    Posts
    15

    Default

    In the meantime, a work-around for this bug is:
    XPath query for -
    (.|*[name()='optionalNode'])[last()]
    followed by a replace string step that clears out the result field when the optional node is not returned.
    The XPath query works by returning the parent node when the optional node is not found. This is because the union operator returns the parent node then the optional node in document order, and the last() function picks the optional node if it exists otherwise the parent 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.