java代码怎么向xml文件中添加多个注释? 本帖最后由 u013156418 于 2014-02-20 12:42:51 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Node common=doc.createComment("注释内容");doc.appendChild(common); 那如果我需要提取这两个注释内容,用正则表达式该怎么做呢?即要得到字符串:<!--########################################@ FileName:test.xml@ Date:2014-02-20 10:24:24@ Editor:Kobe@ Version:1.0.0@ Log:这是一个测试文件########################################--><!--########################################@ FileName:test.xml@ Date:2014-02-20 10:34:24@ Editor:Garnett@ Version:1.0.1@ Log:这是第二个注释########################################--> 那如果我需要提取这两个注释内容,用正则表达式该怎么做呢?即要得到字符串:<!--########################################@ FileName:test.xml@ Date:2014-02-20 10:24:24@ Editor:Kobe@ Version:1.0.0@ Log:这是一个测试文件########################################--><!--########################################@ FileName:test.xml@ Date:2014-02-20 10:34:24@ Editor:Garnett@ Version:1.0.1@ Log:这是第二个注释########################################-->Pattern pattern= Pattern.compile("<!--([\\s\\S]*)-->"); Matcher m=pattern.matcher(xmlString); if(m.find()){ log=xmlString.substring(m.start(), m.end()); }else{ log=null; } 那如果我需要提取这两个注释内容,用正则表达式该怎么做呢?即要得到字符串:<!--########################################@ FileName:test.xml@ Date:2014-02-20 10:24:24@ Editor:Kobe@ Version:1.0.0@ Log:这是一个测试文件########################################--><!--########################################@ FileName:test.xml@ Date:2014-02-20 10:34:24@ Editor:Garnett@ Version:1.0.1@ Log:这是第二个注释########################################-->Pattern pattern= Pattern.compile("<!--([\\s\\S]*)-->"); Matcher m=pattern.matcher(xmlString); if(m.find()){ log=xmlString.substring(m.start(), m.end()); }else{ log=null; }忘了回帖,确实可以,感谢4楼! 请教一个问题 ”事件监听机制,接口放在外部类中“ 的问题 *********初学者关于一个Frame得一个问题!********** 关于clob的问题,请教大家!拜托了!急 Enumeration 是个什么接口哦,有什么用啊? 加急,需要一个JBUILDERX的序列号!! 如何运行有内部类的程序?请进来看看一段code。 简单问题,散分了! 通过JDBC能够连接access吗,不使用ODBC 请教Java Swing 搜狗输入法的问题 把.java 改成 .html 代码不换行原因 鼠标事件的问题
Node common=doc.createComment("注释内容");
doc.appendChild(common);
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:24:24
@ Editor:Kobe
@ Version:1.0.0
@ Log:这是一个测试文件
########################################
-->
<!--
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:34:24
@ Editor:Garnett
@ Version:1.0.1
@ Log:这是第二个注释
########################################
-->
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:24:24
@ Editor:Kobe
@ Version:1.0.0
@ Log:这是一个测试文件
########################################
-->
<!--
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:34:24
@ Editor:Garnett
@ Version:1.0.1
@ Log:这是第二个注释
########################################
-->
Pattern pattern= Pattern.compile("<!--([\\s\\S]*)-->");
Matcher m=pattern.matcher(xmlString);
if(m.find()){
log=xmlString.substring(m.start(), m.end());
}else{
log=null;
}
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:24:24
@ Editor:Kobe
@ Version:1.0.0
@ Log:这是一个测试文件
########################################
-->
<!--
########################################
@ FileName:test.xml
@ Date:2014-02-20 10:34:24
@ Editor:Garnett
@ Version:1.0.1
@ Log:这是第二个注释
########################################
-->
Pattern pattern= Pattern.compile("<!--([\\s\\S]*)-->");
Matcher m=pattern.matcher(xmlString);
if(m.find()){
log=xmlString.substring(m.start(), m.end());
}else{
log=null;
}
忘了回帖,确实可以,感谢4楼!