Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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中修改手动添加的标记值 类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

输出: 当我使用此方法修改html的标记值时,成功地更改了标记名,但在html中再次添加了元数据标记

请给我提个建议

        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");
        }
         }