Results 1 to 8 of 8

Thread: marshalling-transformer returns null for DOMResult and xml for StringResult

  1. #1

    Default marshalling-transformer returns null for DOMResult and xml for StringResult

    Hi,

    I am passing an Employee object on in channel for following configuration:

    Code:
    <si:channel id="in"/>
    <si:channel id="out"/>
    <si:channel id="marshal"/>
    <si:channel id="toSplit"/>
    
    <si-xml:marshalling-transformer marshaller="castorMarshaller" input-channel="in" output-channel="marshal" result-type="DOMResult"/>
    
    <bean id="echo" class="si.EchoTransformer"/>
    
    <si:transformer input-channel="marshal" output-channel="toSplit" ref="echo" method="asDOMNode"/>
    
    <si-xml:xpath-splitter input-channel="toSplit" output-channel="out">
        	<si-xml:xpath-expression expression="/employee/interests/interest"/>
    </si-xml:xpath-splitter>
    This produces following output:

    Code:
    ** Log: Inside Transformer
    [#document: null]
    **
    [interest: null
    ]

    But changing result-type to StringResult and transformer method to asString produces correct xml

    Code:
    ** Log: Inside Transformer
    <?xml version="1.0" encoding="UTF-8"?>
    <employee><location><city>London</city></location><name>Tim</name><interests><interest>architecture</interest></interests></employee>
    **
    <?xml version="1.0" encoding="UTF-8"?><interest>architecture</interest>
    Transformer methods are:
    Code:
    public class EchoTransformer {
    
    	public Node asDOMNode(DOMResult o) {
    		Node node = o.getNode();
    		System.out.println("** Log: Inside Transformer");
    		System.out.println(node);
    		System.out.println("**");
    		return node;
    	}
    	public String asString(Object o) {
    		String str = o.toString();
    		System.out.println("** Log: Inside Transformer");
    		System.out.println(str);
    		System.out.println("**");
    		return str;
    	}
    }
    DOMResult is preferred to avoid intermediate String<->DOM conversions.

    Any help on why DOM node does not work here?

    Thanks

  2. #2
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    In the first case where you are printing out the result of toString on a org.w3c.Node or org.w3c.Document it will give you what you see ie '[interest: null' for the split node and '[#document: null]' for the whole doc. Of course when you log the String representation of the XML you see the whole doc.

    I think possibly your code is working correctly but you are expecting to see something different from the logging?

    Regards

    Jonas
    Jonas Partner
    OpenCredo

  3. #3

    Default

    Thanks for your reply.

    Expected output requirements are:
    Document should not be null
    'interest' should be: 'architecture'

    Because for same input, StringResult gives that output correctly. Just change of internal representation from String to DOM should not affect the output..

  4. #4
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    Both DocumentImpl and NodeImpl in Xerces return null for the getNodeValue() call used in toString() defined in NodeImpl. Hence the output you are seeing or have you converted this to a String to get a full picture of the payload content?

    toString from NodeImpl
    Code:
       /** NON-DOM method for debugging convenience. */
        public String toString() {
            return "["+getNodeName()+": "+getNodeValue()+"]";
        }
    Jonas Partner
    OpenCredo

  5. #5

    Default

    Interesting. But then how to find out if the DOMResult is correct or not? Because, when passed to xpath-splitter, output is again seen as null instead of 'architecture'.

    And if getNodeValue() returns null then what is the use of DOMResult??

    Thanks

  6. #6
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    Still not clear what makes you think this is not working. Regarding
    "output is again seen as null instead of 'architecture'" this is for the same reason. You are printing out a Node so the null does not mean there are no children in the interest Node.

    I would write an integration test that uses XPath to verify the contents of the interest node. '/interest/text()'
    Jonas Partner
    OpenCredo

  7. #7
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    BTW there is no getNodeValue() on DOMResult only getNode().
    Jonas Partner
    OpenCredo

  8. #8

    Default

    Thanks. payload-serializing-transformer showed me that the dom is not null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •