DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
db = dbf.newDocumentBuilder();
Document doc = (Document) db.parse( new FileInputStream(new File(“D:\flow.xml”)));
error logs
java.lang.ClassCastException: class org.apache.xerces.dom.DeferredDocumentImpl cannot be cast to class com.wm.lang.xml.Document (org.apache.xerces.dom.DeferredDocumentImpl and com.wm.lang.xml.Document are in unnamed module of loader java.net.URLClassLoader @63f8709c)
Why not using the Build-In-Services from pub.file-Folder and pub.xml-Folder?
I.e.:
pub.file:getFile (as String)
pub.xml:xmlStringToXMLNode
pub.xml:xmlNodeToDocument
as the error message indicates, the classes used here are not meant for public use.
This is related to the new class loading philosophy in Java.
This was recently discussed here in the community in another thread where some wanted to deploy package which was working on IS 10.5 to IS 10.15 where it was not working any longer.
Unfortunately I cannot find this thread currently.
Why are you casting to document then if all you need to do is parse the XML file in a Java service? Why not threat it as POJO and do everything in java service and push whatever you need back to the pipeline?
I also recommend against making things over complicated. You can still get your document as Holger told and parse however you want to parse it using Java or flow services. I don’t see the benefit off parsing the file manually.
Its not recommended to use that approach as you wont be able to use the created Document to visually manage any mappings. But if you are sure of your use case and really want this you have to make sure you use org.w3c.dom.Document and not com.wm.lang.xml.Document. You can do that by fixing you import statements in the code or specifically fixing the class name as such:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse( new FileInputStream(new File(“D:\flow.xml”)));