此处需用到org.dom4j的jar包
jar包地址:https://mvnrepository.com/artifact/org.dom4j/dom4j/2.1.1
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
public class StringToXML{
public static void main(String[] args) {
String aa = "";//需要转为xml的字符串(必须是xml格式)
try {
Document document =DocumentHelper.parseText(aa);
System.out.println(document.asXML());
} catch (DocumentException e) {
e.printStackTrace();
}
}
}