我正在执行以下代码:
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
doc = docBuilder.parse(sourcepath);
node = doc.getElementsByTagName("NAME").item(0);
node.setTextContent("Bob");
node = doc.getElementsByTagName("ADDRESS1").item(0);
node.setTextContent("US");
node = doc.getElementsByTagName("EMAIL").item(0);
node.setTextContent("abc@defg.com");
dateFormat = new SimpleDateFormat("dd/MM/yy HH:mm");
Date date = new Date();
node = doc.getElementsByTagName("DATESUBMITTED").item(0);
node.setTextContent(dateFormat.format(date));
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
System.out.println(rail_feedback_dest);
StreamResult result = new StreamResult(new File(destinationPath)); transformer.transform(source, result);
但是当我在变量“sourcepath”和“destinationPath”中给出路径时,它给出错误:java.net.MalformedURLException:no protocol: 但是在提供完整路径而不是在变量中提供它时,代码工作正常....