Java 如何在html中修改手动添加的标记值 类HtmlTagmodifier{ 公共字符串htmlFileWriter(字符串cfile、字符串Listname、字符串Nodename、字符串nodevalue){ 试一试{ 文件fhtmlFile=新文件(cfile); DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder=dbFactory.newDocumentBuilder(); documentdoc=dBuilder.parse(fhtmlFile); doc.getDocumentElement().normalize(); NodeList nList=doc.getElementsByTagName(列表名); 对于(int-temp=0;temp
输出: 当我使用此方法修改html的标记值时,成功地更改了标记名,但在html中再次添加了元数据标记 请给我提个建议Java 如何在html中修改手动添加的标记值 类HtmlTagmodifier{ 公共字符串htmlFileWriter(字符串cfile、字符串Listname、字符串Nodename、字符串nodevalue){ 试一试{ 文件fhtmlFile=新文件(cfile); DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder=dbFactory.newDocumentBuilder(); documentdoc=dBuilder.parse(fhtmlFile); doc.getDocumentElement().normalize(); NodeList nList=doc.getElementsByTagName(列表名); 对于(int-temp=0;temp,java,html,apache-poi,Java,Html,Apache Poi,输出: 当我使用此方法修改html的标记值时,成功地更改了标记名,但在html中再次添加了元数据标记 请给我提个建议 class HtmlTagmodifier { public String htmlFileWriter(String cfile, String Listname, String Nodename, String nodevalue) { try { File fhtmlFile = new File(cf
class HtmlTagmodifier {
public String htmlFileWriter(String cfile, String Listname, String Nodename, String nodevalue) {
try {
File fhtmlFile = new File(cfile);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fhtmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName(Listname);
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
eElement.getElementsByTagName(Nodename).item(0).setTextContent(nodevalue);
}
}
Source source = new DOMSource(doc);
Result htmlresult = new StreamResult(fhtmlFile);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, htmlresult);
result2 = "Success";
} catch (Exception e) {
e.printStackTrace();
log.error("Error in html file writing " + e.toString());
JOptionPane.showMessageDialog(null, "Error in html file writing " + e.toString());
result2 = "Failed";
}
return result2;
}
public static void main(String[] args) {
HtmlTagmodifier.htmlfilewriter("test.html", "details", "customername", "customernamexxxxxx");
}
}