jDom生成xml文件

1.导入对应的包

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
  1. 代码
/**
	 * 得到xml文件
	 * 
	 * @param beanList
	 * @return String
	 */
	private  String getXml(List<FeildReturnMap> beanList,TableInfo info) throws Exception{
		        String result = ""; 
		        //跟节点名称
		        Element root = new Element("result"); 
		        Document doc = new Document(root); 
		        List<String> externalFields = info.getExternalFields();
		        for (int i = 0; i < beanList.size(); i++) {
					//子节点名称
		            Element element = new Element("item"); 

		            //单个项的名称和值
		            element.addContent(new Element("userName").setText("sbsbsb")); 

//		              
		            root.addContent(element); 
		        } 
		  
		        XMLOutputter XMLOut = new XMLOutputter(); 
		          
		         result = XMLOut.outputString(doc); 
		        return result; 
	}
  1. 结果
    jDom生成xml文件

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-09-06
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-10-23
  • 2021-10-02
  • 2022-01-01
  • 2021-07-11
  • 2021-08-23
  • 2022-12-23
相关资源
相似解决方案