P
pulvertum
Hello,
I need an org.w3c.dom.Document so I can pass them to do a
transformation of my XML using XSL (to another XML as result).
I've tried several solutions but didn't have the desired result:
SOLUTION 1 using StreamOutput:
StreamSource streamXSL = new StreamSource(new
File(txtFileXSL));
Templates templates =
TransformerFactory.newInstance().newTemplates(streamXSL);
Transformer parser = null;
// tranformation using STREAMOUTPUT
StreamSource streamXML = new StreamSource(new
File(txtFileXMLSource));
StreamResult streamOutput = new StreamResult(System.out);
parser = templates.newTransformer();
parser.transform(streamXML, streamOutput);
--> does the parsing CORRECT but I don't have a
org.w3c.dom.Document/Node as a result
SOLUTION 2 :
// transformation using DOMRESULT
DOMResult domResult = new DOMResult();
parser = templates.newTransformer();
parser.transform(streamXML, domResult);
--> does NOT WORK if I do domResult.getNode().getFirstChild() then my
rootnode is empty?????
SOLUTION 3 (other builder/parser):
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
org.w3c.dom.Document docXSL = parser.parse(fileXSL);
--> I don't get any errormessages but again if I ask for the rootnode,
it is EMPTY???
How can I retrieve an org.w3c.dom.Document/Node without having an
empty rootnode?
I'm sure my XSL and/or XSL is correctly because using solution 1 with
a StreamOutput doesn't cause any problems!!
Hopefully someone can help me, I'm out of inspiration!
I need an org.w3c.dom.Document so I can pass them to do a
transformation of my XML using XSL (to another XML as result).
I've tried several solutions but didn't have the desired result:
SOLUTION 1 using StreamOutput:
StreamSource streamXSL = new StreamSource(new
File(txtFileXSL));
Templates templates =
TransformerFactory.newInstance().newTemplates(streamXSL);
Transformer parser = null;
// tranformation using STREAMOUTPUT
StreamSource streamXML = new StreamSource(new
File(txtFileXMLSource));
StreamResult streamOutput = new StreamResult(System.out);
parser = templates.newTransformer();
parser.transform(streamXML, streamOutput);
--> does the parsing CORRECT but I don't have a
org.w3c.dom.Document/Node as a result
SOLUTION 2 :
// transformation using DOMRESULT
DOMResult domResult = new DOMResult();
parser = templates.newTransformer();
parser.transform(streamXML, domResult);
--> does NOT WORK if I do domResult.getNode().getFirstChild() then my
rootnode is empty?????
SOLUTION 3 (other builder/parser):
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
org.w3c.dom.Document docXSL = parser.parse(fileXSL);
--> I don't get any errormessages but again if I ask for the rootnode,
it is EMPTY???
How can I retrieve an org.w3c.dom.Document/Node without having an
empty rootnode?
I'm sure my XSL and/or XSL is correctly because using solution 1 with
a StreamOutput doesn't cause any problems!!
Hopefully someone can help me, I'm out of inspiration!