HotoSpoobby
New Member
I'm trying to validate a GE ECG XML file. I do not have control over the xml or the dtd.My code is pulling in the main DTD. That DTD includes a second DTD, which my code cannot find:\[code\]C:\Programming\workspaces\myProject\I2.dtd (The system cannot find the file specified)\[/code\]How can I resolve this?Here's part of the XML:\[code\]<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE RestingECG SYSTEM "restecg.dtd">\[/code\]Here's restecg.dtd:\[code\]<?xml version="1.0" encoding="UTF-8"?><!ENTITY % I2DTD SYSTEM "I2.dtd">%I2DTD;<!ENTITY % field SYSTEM "restecgfield.dtd">%field;<!ELEMENT RestingECG (...\[/code\]Here's I2.dtd:\[code\]<?xml version="1.0" encoding="UTF-8"?><!ENTITY % I2field SYSTEM "I2field.dtd">%I2field;\[/code\]Here's I2field.dtd:\[code\]<!-- Field definition --><!ENTITY % MUSEDict "0"><!ENTITY % HISDict "1">\[/code\]Here's my code:\[code\]private Boolean validateDTD(String dtdPath, String xmlPath) { System.out.println("xmlPath = " + xmlPath); System.out.println("dtdPath = " + dtdPath); try{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { //Ignore the fatal errors public void fatalError(SAXParseException exception)throws SAXException { } //Validation errors public void error(SAXParseException e)throws SAXParseException { System.out.println("Error at " +e.getLineNumber() + " line."); System.out.println(e.getMessage()); System.exit(0); ISVALIDXML = false; } //Show warnings public void warning(SAXParseException err)throws SAXParseException{ System.out.println(err.getMessage()); System.exit(0); ISVALIDXML = false; } }); Document xmlDocument = builder.parse(new FileInputStream(xmlPath)); DOMSource source = new DOMSource(xmlDocument); StreamResult result = new StreamResult(System.out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdPath); transformer.transform(source, result); } catch (Exception e) { System.out.println(e.getMessage()); ISVALIDXML = false; } return ISVALIDXML;} \[/code\]I'm open to fixing this code or using an entirely new approach.