Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document

Highlighted
Six Stars

Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document

Recently we have upgraded a talend job from TOS 5.3.2 to 6.1.0 but started getting a compile time error "Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document". This is happening while saving a data from tESBProviderRequest into xml file.

 

PS : This was working fine in 5.3.2 so I think there should be no concern of job design. Regarding the fix, I am sure it can be done from manual conversions. But what I want to know is, Is it the version problem?

Community Manager

Re: Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document

This is an annoying "feature" when working with XML. However it usually is experienced if you use your own Java code to work with XML. An easy way to get round this is to convert the XML (of class type  org.w3c.dom.Document) to a String, remove the XML signature and then use the tConvertType component to convert from String to Talend' Document class.

 

It's a pain, but it works. I'm not sure why Talend have their own Document class for XML, but I have built a routine with Java to handle this scenario. 

 

Here is some code.....

To remove the XML header from the String....

    public static String removeXMLHeader(String xml){
    	if(xml!=null){
    		xml = xml.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();
    	}
    	
    	return xml;
    }

To convert from an org.w3c.Document to String....

    public static String getStringFromDocument(Document doc)
    {
        try
        {
           DOMSource domSource = new DOMSource(doc);
           StringWriter writer = new StringWriter();
           StreamResult result = new StreamResult(writer);
           TransformerFactory tf = TransformerFactory.newInstance();
           Transformer transformer = tf.newTransformer();
           transformer.transform(domSource, result);
           return writer.toString();
        }
        catch(TransformerException ex)
        {
           ex.printStackTrace();
           return null;
        }
    } 
Six Stars

Re: Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document

Hi Richard,

thanks for the reply. 

 

Eventually i got it worked with parsing. ParserUtils.parseTo_Document

However my question is still the same. It was working fine in 5.3.2 (there i did not need any conversion), why it caused problem when the job is upgraded to 6.1.0 ?

Community Manager

Re: Type mismatch : can not convert from org.w3c.dom.Document to routines.system.Document

I don't believe Talend introduced a change to how it interacts with XML between those versions. I certainly don't remember having to significantly change anything I worked on. The only thing I can think of is maybe the change of Java version. It would be very hard to diagnose precisely why you experienced this without having your code and seeing this for myself. 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads