w3c.dom.Document
can be used as a Node
, but when I try this
public static Object tranform(Source source) {
Object result = null;
try {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer newTransformer = tf.newTransformer();
newTransformer.transform(source, (Result) result);
} catch (TransformerException ex) {
Logger.getLogger(XMLUtils.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
on the other file
Document doc = (Document) XMLUtils.tranform(source);
// pass this doc to a function that that a Node typed parameter
if (node == null) {
return;
} else {
...
}
node
would always be null, and it has no child node, too.
I tried to convert every type of source to every type of result, coders will cast the returned result to the correct type they need. So could you please
1) Explain my error?
2) Give me a hint how to implement that purpose?
Thank you and best regards