[ 
https://issues.apache.org/jira/browse/JXPATH-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12554039
 ] 

Michele Vivoda commented on JXPATH-83:
--------------------------------------

A workaround for DOM based models is to use selectSingleNode and 
retrieve the string value using something like getStringValueOfNode(node);
When using selectNodes instead return an empty string when iterator is empty 
otherwise 
return getStringValueOfNode(node) where {node} is the first node of the list.

   static String getStringValueOfNode(final Node n)
    {
        final StringBuffer buf = new StringBuffer();
        toStringAppend(n, buf);
        return buf.toString();
    }
    private static void toStringAppend(final Node n, final StringBuffer buf)
    {
        final String value = n.getNodeValue();
        if (value == null)
        {
            Node current= n.getFirstChild();
            while(current!=null)
            {
                toStringAppend(current, buf);
                current = current.getNextSibling();
            }
        }
        else if (!(n instanceof Comment)) buf.append(value);
    }

> JXpath automatically trims string values
> ----------------------------------------
>
>                 Key: JXPATH-83
>                 URL: https://issues.apache.org/jira/browse/JXPATH-83
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.2 Final
>            Reporter: Wim Biesemans
>             Fix For: 1.3
>
>
> When an xml contains a value with leading or trailing spaces, JXPath trims 
> this value.
> example: <value>     12324 56</value> is retrieved by JXPath as : '1234 56' 
> while I expect '     1234 56'.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to