0

dom4j 没有问题

String text = "<person> <name>James</name> </person>";
Document document = DocumentHelper.parseText(text);

我需要的是这个

String text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"+
"<person> <name>James</name> </person>";
Document document = DocumentHelper.parseText(text);

但它会引发异常。

org.dom4j.DocumentException: Error on line 1 of document  : parsing initialization error: org.gjt.xpp.XmlPullParserException: only whitespace content allowed outside root element at line 1 and column 1 seen 
4

1 回答 1

1

我发现了问题。下面的前一行是失败的。后线工作。

Document output = DocumentHelper.parseText(response.getEntity(String.class));

Document output = DocumentHelper.parseText(response.getEntity(String.class).trim());
于 2012-10-15T18:21:07.970 回答