XML transformation/parsing problem

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top