目前我正在使用XML,JSP和Activiti Workflow Engine。在我的项目中,我有以下流程:
我已成功更新我的xml文件并部署该过程,但是当我遇到XML标记名称的问题时。问题是:
我想是因为我需要在运行部署之前先刷新XML文件。但我不知道如何在JSP或Java上这样做。有人可以帮帮我吗?感谢
这是我的代码:
try {
String filepath = "path/to/the/filename.bpmn20.xml";
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
// Get the process element by tag name directly
Node userTask = doc.getElementsByTagName("userTask").item(0);
// update userTask attribute
NamedNodeMap attr = userTask.getAttributes();
Node nodeAttr = attr.getNamedItem("name");
nodeAttr.setTextContent("Review and Sign Form "+id);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(filepath));
transformer.transform(source, result);
System.out.println("Done");
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException sae) {
sae.printStackTrace();
}