如:html="<container:content> "+
" <b:selectText> "+
" <input type=\"text\" id=\"a\"/> "+
" </b:selectText> "+
"</container:content> ";用正则表达式??
" <b:selectText> "+
" <input type=\"text\" id=\"a\"/> "+
" </b:selectText> "+
"</container:content> ";用正则表达式??
public static void main(String[] args)throws Exception{
String s="<table>" +
"<tr><td></td></tr>" +
"<tr><td></td></tr>" +
"<tr><td></td></tr>" +
"</table>";
Tidy tidy=new Tidy(); ByteArrayInputStream bais=new ByteArrayInputStream (s.getBytes());
FileOutputStream fos=new FileOutputStream(new File("d:/tidy.xml"));
tidy.parse(bais, fos);
}
就会报错!如何简单的判断如题描述的格式?只需要检查标签名以及内嵌标签名是否完整。。
String str = ...;
String regEx = "<([^<>]+)(/>|>[^<>]*</\\1>)";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
while (m.find()) {
str = str.replaceAll(regEx, "");
m = p.matcher(str);
}
if (str.equals(""))
System.out.println("完整");
else
System.out.println("不完整");