Announcement Announcement Module
Collapse
No announcement yet.
marshalling-transformer returns null for DOMResult and xml for StringResult Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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..

      Comment


      • #4
        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()+"]";
            }

        Comment


        • #5
          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

          Comment


          • #6
            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()'

            Comment


            • #7
              BTW there is no getNodeValue() on DOMResult only getNode().

              Comment


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

                Comment

                Working...
                X