在JDOM里,我用XMLOutputter类的output方法,把DOCUMNET对象输出到字符串,为什么St会有<xml version=..>开头,如何去除ByteArrayOutputStream b = new ByteArrayOutputStream()
xmloutputter.output(document,b);
b.toString(); 就有<xml version=..>开头,document对象里一定要包含<xml version=..>?
如何去除在output()时谢谢
xmloutputter.output(document,b);
b.toString(); 就有<xml version=..>开头,document对象里一定要包含<xml version=..>?
如何去除在output()时谢谢
你可以最后用replaceAll()从字符串里删除掉
replaceAll()要怎么写,才能把<xml version=..>和换行符也去除,谢谢
就是删除不了,请哪位大侠出手
删掉就不是xml文件了...
现在问题是replaceAll方法,为什么下面语句删除不了呢
str = str.replaceAll(" <?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 谢谢
String desc, String username) {
String xmlPath = "storyboard/XML/db.xml";
XMLOutputter outputter = null;
SAXBuilder saxBuilder = new SAXBuilder(false);
try {
Document doc = saxBuilder.build(xmlPath);
Element goodsinfo = doc.getRootElement();
List goods = goodsinfo.getChildren("goods");
for (int i = 1; i < goods.size() + 1; i++) {
Element current = (Element) goods.get(i - 1); String _area = current.getChild("area").getText().toString();
String _catalog = current.getChild("catalog").getText().
toString();
String _name = current.getChild("name").getText().toString();
String _description = current.getChild("description").getText().
toString();
String _username = current.getChild("username").getText().
toString();
if (_area.equals(area) && _catalog.equals(catalog) &&
_name.equals(name) && _description.equals(desc) &&
_username.equals(username)) { current.getParentElement().removeContent(current);
System.out.println("doDeleteFromXMLFile() is called.");
break;
}
}
//System.out.println("checked1");
Format format = Format.getCompactFormat();
format.setIndent(" ");
format.setEncoding("UTF-8"); outputter = new XMLOutputter(format);
FileWriter writer = new FileWriter(xmlPath);
outputter.output(goodsinfo, writer);
//Writer.flush();
writer.close();
//System.out.println("checked2"); } catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}