快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

javaxml生成代码 java jxl生成excel

如何用java生成一个xml文件

一个XML文档,可以先构造一个DOM,然后将DOM转化为xml序列,输出或者生成文件。package test;

网站设计、做网站的开发,更需要了解用户,从用户角度来建设网站,获得较好的用户体验。创新互联公司多年互联网经验,见的多,沟通容易、能帮助客户提出的运营建议。作为成都一家网络公司,打造的就是网站建设产品直销的概念。选择创新互联公司,不只是建站,我们把建站作为产品,不断的更新、完善,让每位来访用户感受到浩方产品的价值服务。

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

public class Test {

public static void generate(){

try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.newDocument();

document.setXmlVersion("1.0");

document.setXmlStandalone(true);

Element root = document.createElement_x("MobileNet"); //创建根节点

document.appendChild(root); //将根节点添加到Document对象中

Element pageElement = document.createElement_x("page"); //设置第一个page元素到

pageElement.setAttribute("name", "list.jsp"); //设置page节点的name属性

Element methodElement = document.createElement_x("method"); //设置method节点

methodElement.setTextContent("get"); //给method设置值

pageElement.appendChild(methodElement); //添加method节点到page节点内

Element displayElement = document.createElement_x("display"); //设置method节点

displayElement.setTextContent("list撒旦发放"); //给display设置值

pageElement.appendChild(displayElement); //添加display节点到page节点内

Element request_paramElement = document.createElement_x("request_param");

request_paramElement.setTextContent("request_param1|request_param2");

pageElement.appendChild(request_paramElement);

root.appendChild(pageElement);

pageElement = document.createElement_x("page"); //设置第二个page元素到

pageElement.setAttribute("name", "content.jsp"); //设置page节点的name属性

methodElement = document.createElement_x("method");

methodElement.setTextContent("post");

pageElement.appendChild(methodElement);

displayElement = document.createElement_x("display");

displayElement.setTextContent("content");

pageElement.appendChild(displayElement);

Element url_titleElement = document.createElement_x("url_title"); //设置url_title节点

url_titleElement.setTextContent("title,publisher,published_calendar"); //给url_title设置值

pageElement.appendChild(url_titleElement); //添加url_title节点到page节点内

root.appendChild(pageElement); //将page段加人根节点内

TransformerFactory transFactory = TransformerFactory.newInstance(); //开始把Document映射到文件

Transformer transFormer = transFactory.newTransformer();

DOMSource domSource = new DOMSource(document); //设置输出结果

File file = new File("MobileNetRule.xml"); //生成xml文件

if (!file.exists()) {

file.createNewFile();

}

FileOutputStream out = new FileOutputStream(file); //文件输出流

StreamResult xmlResult = new StreamResult(out); //设置输入源

transFormer.transform(domSource, xmlResult); //输出xml文件

System.out.println(file.getAbsolutePath()); //测试文件输出的路径

TransformerFactory tf = TransformerFactory.newInstance();

Transformer t = tf.newTransformer();

t.setOutputProperty("{/encoding/}","GB2312/");

ByteArrayOutputStream boc = new ByteArrayOutputStream();

t.transform(new DOMSource(document), new StreamResult(boc));

String xmlstring = boc.toString();

System.out.println(xmlstring);

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args){

Test.generate();

}

}

如何用java代码创建xml文件

用java自带的就可以,有问题可以问我

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

//构造

public XMLUtil(String name) throws ParserConfigurationException {

filename = name;

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

builder = factory.newDocumentBuilder();

document = builder.newDocument();

}

/**

* 保存到文件

*/

public void toSave() {

try {

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transformer = tf.newTransformer();

DOMSource source = new DOMSource(document);

transformer.setOutputProperty(OutputKeys.ENCODING, "GB2312");

transformer.setOutputProperty(OutputKeys.INDENT, "yes");

PrintWriter pw = new PrintWriter(new FileOutputStream(filename));

StreamResult result = new StreamResult(pw);

transformer.transform(source, result);

} catch (TransformerException mye) {

mye.printStackTrace();

} catch (IOException exp) {

exp.printStackTrace();

}

}

JAVA 生成xml格式,具体格式如下,请问JAVA方法怎么写

import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.w3c.dom.*;import org.xml.sax.SAXException;import javax.xml.parsers.*;import javax.xml.transform.*;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.*;import javax.xml.xpath.*;public class Test { public static void main(String[] args) { DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); Element theBook=null, theElem=null, root=null; try { factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db=factory.newDocumentBuilder(); Document xmldoc=db.parse(new File("Test1.xml")); root=xmldoc.getDocumentElement(); theBook=(Element) selectSingleNode("/books/book[name='哈里波特']", root); System.out.println("--- 查询找《哈里波特》 ----"); Element nameNode=(Element)theBook.getElementsByTagName("price").item(0); String name=nameNode.getFirstChild().getNodeValue(); System.out.println(name); output(theBook); System.out.println("=============selectSingleNode(books/book[name='哈里波特'], root)=================="); //--- 新建一本书开始 ---- theBook=xmldoc.createElement("book"); theElem=xmldoc.createElement("name"); theElem.setTextContent("新书"); theBook.appendChild(theElem); theElem=xmldoc.createElement("price"); theElem.setTextContent("20"); theBook.appendChild(theElem); theElem=xmldoc.createElement("memo"); theElem.setTextContent("新书的更好看。"); theBook.appendChild(theElem); root.appendChild(theBook); System.out.println("--- 新建一本书开始 ----"); output(xmldoc); System.out.println("=============================="); //--- 新建一本书完成 ---- //--- 下面对《哈里波特》做一些修改。 ---- //--- 查询找《哈里波特》---- //--- 此时修改这本书的价格 ----- theBook.getElementsByTagName("price").item(0).setTextContent("15");//getElementsByTagName返回的是NodeList,所以要跟上item(0)。另外,getElementsByTagName("price")相当于xpath的".//price"。 System.out.println("--- 此时修改这本书的价格 ----"); output(theBook); //--- 另外还想加一个属性id,值为B01 ---- theBook.setAttribute("id", "B01"); System.out.println("--- 另外还想加一个属性id,值为B01 ----"); output(theBook); //--- 对《哈里波特》修改完成。 ---- //--- 要用id属性删除《三国演义》这本书 ---- theBook=(Element) selectSingleNode("/books/book[@id='B02']", root); System.out.println("--- 要用id属性删除《三国演义》这本书 ----"); output(theBook); theBook.getParentNode().removeChild(theBook); System.out.println("--- 删除后的XML ----"); output(xmldoc); //--- 再将所有价格低于10的书删除 ---- NodeList someBooks=selectNodes("/books/book[price10]", root); System.out.println("--- 再将所有价格低于10的书删除 ---"); System.out.println("--- 符合条件的书有 "+someBooks.getLength()+"本。 ---"); for(int i=0;isomeBooks.getLength();i++) { someBooks.item(i).getParentNode().removeChild(someBooks.item(i)); } output(xmldoc); saveXml("Test1_Edited.xml", xmldoc); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void output(Node node) {//将node的XML字符串输出到控制台 TransformerFactory transFactory=TransformerFactory.newInstance(); try { Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty("encoding", "gb2312"); transformer.setOutputProperty("indent", "yes"); DOMSource source=new DOMSource(); source.setNode(node); StreamResult result=new StreamResult(); result.setOutputStream(System.out); transformer.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } public static Node selectSingleNode(String express, Object source) {//查找节点,并返回第一个符合条件节点 Node result=null; XPathFactory xpathFactory=XPathFactory.newInstance(); XPath xpath=xpathFactory.newXPath(); try { result=(Node) xpath.evaluate(express, source, XPathConstants.NODE); } catch (XPathExpressionException e) { e.printStackTrace(); } return result; } public static NodeList selectNodes(String express, Object source) {//查找节点,返回符合条件的节点集。 NodeList result=null; XPathFactory xpathFactory=XPathFactory.newInstance(); XPath xpath=xpathFactory.newXPath(); try { result=(NodeList) xpath.evaluate(express, source, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return result; } public static void saveXml(String fileName, Document doc) {//将Document输出到文件 TransformerFactory transFactory=TransformerFactory.newInstance(); try { Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty("indent", "yes"); DOMSource source=new DOMSource(); source.setNode(doc); StreamResult result=new StreamResult(); result.setOutputStream(new FileOutputStream(fileName)); transformer.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }} XML:?xml version="1.0" encoding="GBK"?booksbookname哈里波特/nameprice10/pricememo这是一本很好看的书。/memo/bookbook id="B02"name三国演义/nameprice10/pricememo四大名著之一。/memo/bookbook id="B03"name水浒/nameprice6/pricememo四大名著之一。/memo/bookbook id="B04"name红楼/nameprice5/pricememo四大名著之一。/memo/book/books

怎样将xml档案生成java程式码

怎样将xml档案生成java程式码 xml是有格式的档案,到底里面储存了什么资料,得知道,才能办法处理

java程式码怎样生成csv档案

我来说一下大致的实现步骤,具体实现需要你自己去写了

1.检索资料,检索到的资料假定为一个list

2.你需要自己写一个objectToString之类的方法来把检索到的资料转化为一个String或StringBuffer,就是往各栏位间插",",往个记录间插"\r\n",如此这类的转换,假定转换好的字串为strResult.

3.然后用下面的程式码写在后台来控制下载,档名那里你可以把时间格式控制好,或者用前台传过来的引数做名字。

response.setContentType("application/download;charset=UTF-8");

response.setHeader("Content-disposition","attachment;filename=\"" +new Date()+".csv\"");

Java程式码完成后,怎样生成档案?

JCreator Pro 点一下编译按钮不就行了吗,再点执行按钮就运行了

eclipse通过xml档案如何找到java程式码

一、配置指南:

1、Eclipse中类档案(*.java)自动补全配置:

Windows-preferance-java-Editor-Content Assist

面板最下端 Auto Activation 将Auto activation triggers for Java后面的文字框中的“.”替换成“abcdefghijklmnopqrstuvwABCDEFGHIJKLMNOPQRSTUVWXYZ.”(注意后面还有一个".")

2、Eclipse中*.xml档案自动补全配置:

Windows-preferance-XML-XML Files-Editor-Content Assist

面板最上端 Auto Activation 将Prompt when these characters are inserted后面的文字框中的“=:”替换成“=:abcdefghijklmnopqrstuvwABCDEFGHIJKLMNOPQRSTUVWXYZ ”(注意后面还有一个空格)

二、使用指南:

在需要程式码自动补全的地方直接按ALT+/,就会出现类似如下图所示的效果,选择就可以啦:

java程式码生成dat档案

File filename = new File("F:\\zd.dat");

说明:dat可以改成任何副档名,是自己可以定义的,如下:

public void createFile(){path表示所建立档案的路径String path = "d:/tr/rt";File f = new File(path);if(!f.exists()){f.mkdirs();} fileName表示建立的档名;为txt型别;String fileName="test.txt";File file = new File(f,fileName);if(!file.exists()){try {file.createNewFile();} catch (IOException e) { TODO Auto-generated catch blocke.printStackTrace();}}}现在可以在d:/tr/rt 目录下找到test.txt档案

怎么生成pdf档案 java程式码

使用iText外挂,这是著名的开放原始码的站点sourcefe一个专案。网上很多例子,自己搜一下,不给你举例了。

java 怎样解析 excel生成的xml档案

java解析excel生成的xml档案的方法是使用dom4j实现的。

dom4j是一个简单的开源库,用于处理XML、 XPath和XSLT,它基于Java平台,使用Java的集合框架,全面集成了DOM,SAX和JAXP。

1、excel生成的xml样例档案:

?xml version="1.0"?

?mso-application progid="Excel.Sheet"?

Workbook xmlns="urn:schemas-microsoft-:office:spreadsheet"

xmlns:o="urn:schemas-microsoft-:office:office"

xmlns:x="urn:schemas-microsoft-:office:excel"

xmlns:ss="urn:schemas-microsoft-:office:spreadsheet"

xmlns:=":w3./TR/REC-40"

DocumentProperties xmlns="urn:schemas-microsoft-:office:office"

Created2006-09-16T00:00:00Z/Created

LastSaved2016-07-25T03:26:50Z/LastSaved

Version14.00/Version

/DocumentProperties

OfficeDocumentSettings xmlns="urn:schemas-microsoft-:office:office"

AllowPNG/

RemovePersonalInformation/

/OfficeDocumentSettings

ExcelWorkbook xmlns="urn:schemas-microsoft-:office:excel"

WindowHeight7956/WindowHeight

WindowWidth14808/WindowWidth

WindowTopX240/WindowTopX

WindowTopY168/WindowTopY

ActiveSheet2/ActiveSheet

ProtectStructureFalse/ProtectStructure

ProtectWindowsFalse/ProtectWindows

/ExcelWorkbook

Styles

Style ss:ID="Default" ss:Name="Normal"

Alignment ss:Vertical="Bottom"/

Borders/

Font ss:FontName="宋体" x:CharSet="134" ss:Size="11" ss:Color="#000000"/

Interior/

NumberFormat/

Protection/

/Style

Style ss:ID="s16" ss:Name="好"

Font ss:FontName="宋体" x:CharSet="134" ss:Size="11" ss:Color="#006100"/

Interior ss:Color="#C6EFCE" ss:Pattern="Solid"/

/Style

Style ss:ID="s17"

Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:Indent="1"

ss:WrapText="1"/

Font ss:FontName="宋体" x:CharSet="134" ss:Size="8" ss:Color="#686868"/

NumberFormat ss:Format="@"/

/Style

Style ss:ID="s18" ss:Parent="s16"

Alignment ss:Vertical="Bottom"/

/Style

Style ss:ID="s19"

NumberFormat ss:Format="yyyy/m/d\ h:mm:ss"/

/Style

/Styles

Worksheet ss:Name="Sheet1"

Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="3" x:FullColumns="1"

x:FullRows="1" ss:DefaultRowHeight="14.4"

Row

CellData ss:Type="String"工号/Data/Cell

CellData ss:Type="String"姓名 /Data/Cell

Cell ss:Index="5"Data ss:Type="String"工号/Data/Cell

CellData ss:Type="String"姓名/Data/Cell

/Row

Row

CellData ss:Type="Number"111/Data/Cell

CellData ss:Type="String"张三/Data/Cell

Cell ss:Index="5"Data ss:Type="Number"111/Data/Cell

Cell ss:Formula="=VLOOKUP(R2C5:R3C5,RC[-5]:R[1]C[-4],2)"Data

ss:Type="String"张三/Data/Cell

/Row

Row

CellData ss:Type="Number"112/Data/Cell

CellData ss:Type="String"李四/Data/Cell

Cell ss:Index="5"Data ss:Type="Number"112/Data/Cell

Cell ss:Formula="=VLOOKUP(R2C5:R3C5,RC[-5]:R[1]C[-4],2)"Data

ss:Type="String"李四/Data/Cell

/Row

/Table

WorksheetOptions xmlns="urn:schemas-microsoft-:office:excel"

PageSetup

Header x:Margin="0.3"/

Footer x:Margin="0.3"/

PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/

/PageSetup

Panes

Pane

Number3/Number

ActiveRow7/ActiveRow

ActiveCol5/ActiveCol

/Pane

/Panes

ProtectObjectsFalse/ProtectObjects

ProtectScenariosFalse/ProtectScenarios

/WorksheetOptions

/Worksheet

/Workbook

2、java解析程式码:

import java.io.File;

import java.util.Iterator;

import .dom4j.Attribute;

import .dom4j.Document;

import .dom4j.Element;

import .dom4j.io.SAXReader;

public class Demo {

public static void main(String[] args) throws Exception {

SAXReader reader = new SAXReader();

Document document = reader.read(new File("person.xml"));

Element root = document.getRootElement();

Iterator it = root.elementIterator();

while (it.hasNext()) {

Element element = (Element) it.next();

未知属性名称情况下

/*Iterator attrIt = element.attributeIterator();

while (attrIt.hasNext()) {

Attribute a = (Attribute) attrIt.next();

System.out.println(a.getValue());

}*/

已知属性名称情况下

System.out.println("id: " + element.attributeValue("id"));

未知元素名情况下

/*Iterator eleIt = element.elementIterator();

while (eleIt.hasNext()) {

Element e = (Element) eleIt.next();

System.out.println(e.getName() + ": " + e.getText());

}

System.out.println();*/

已知元素名情况下

System.out.println("title: " + element.elementText("title"));

System.out.println("author: " + element.elementText("author"));

System.out.println();

}

}

}

求一段 读出\修改 xml档案的java程式码

import .dom4j.Element;

import .dom4j.tree.DefaultElement;

import .dom4j.tree.DefaultDocument;

上面是主要的包!

String xml = "";

Element _root = new DefaultElement("Business");

Element _node = _root.addElement("Output");

try {

_node.addElement("Password").addText("123");

_node.addElement("ReturnData").addText("1");

_node.addElement("ReturnInfo").addText("登陆成功");

}

catch (Exception ex) {

ex.printStackTrace();

}

DefaultDocument doc = new DefaultDocument(_root);

xml = doc.asXML();

上面是生成XML。

怎么通过java程式码向xml档案中添加注释

package .tuobao.test;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.util.Iterator;

import java.util.List;

import .dom4j.Attribute;

import .dom4j.Document;

import .dom4j.DocumentHelper;

import .dom4j.Element;

import .dom4j.io.OutputFormat;

import .dom4j.io.SAXReader;

import .dom4j.io.XMLWriter;

public class testDom4j {

private static final String path = "f:" + java.io.File.separator

+ "eee.xml";

/**

* @param args

*/

public static void main(String[] args) {

System.out.println(createXMLFile(path));

System.out.println(modiXMLFile(path, path));

System.out.println(formatXMLFile(path));

}

/**

* 建立一个XML文件,文件名由输入属性决定

*

* @param param

* filename 需建立的档名

* @return返回操作结果, 0表失败, 1表成功

*/

public static int createXMLFile(String filename) {

/** 返回操作结果, 0表失败, 1表成功 */

int returnValue = 0;

/** 建立document物件 */

Document document = DocumentHelper.createDocument();

/** 建立XML文件的根books */

Element booksElement = document.addElement("books");

/** 加入一行注释 */

booksElement.addComment("This is a test for dom4j, holen, 2004.9.11");

/** 加入第一个book节点 */

Element bookElement = booksElement.addElement("book");

/** 加入show属性内容 */

bookElement.addAttribute("show", "yes");

/** 加入title节点 */

Element titleElement = bookElement.addElement("title");

/** 为title设定内容 */

titleElement.setText("Dom4j Tutorials");

/** 类似的完成后两个book */

bookElement = booksElement.addElement("book");

bookElement.addAttribute("show", "yes");

titleElement = bookElement.addElement("title");

titleElement.setText("Lucene Studing");

bookElement = booksElement.addElement("book");

bookElement.addAttribute("show", "no");

titleElement = bookElement.addElement("title");

titleElement.setText("Lucene in Action");

/** 加入owner节点 */

Element ownerElement = booksElement.addElement("owner");

ownerElement.setText("O'Reilly");

try {

/** 将document中的内容写入档案中 */

XMLWriter writer = new XMLWriter(new FileWriter(new java.io.File(

filename)));

writer.write(document);

writer.flush();

writer.close();

/** 执行成功,需返回1 */

returnValue = 1;

} catch (Exception ex) {

returnValue = 0;

ex.printStackTrace();

}

return returnValue;

}

/**

* 修改XML档案中内容,并另存为一个新档案 重点掌握dom4j中如何新增节点,修改节点,删除节点

*

* @param filename

* 修改物件档案

* @param newfilename

* 修改后另存为该档案

* @return 返回操作结果, 0表失败, 1表成功

*/

public static int modiXMLFile(String filename, String newfilename) {

int returnValue = 0;

try {

SAXReader saxReader = new SAXReader();

Document document = saxReader.read(new java.io.File(filename));

/** 修改内容之一: 如果book节点中show属性的内容为yes,则修改成no */

/** 先用xpath查询物件 */

List list = document.selectNodes("/books/book/@show");

Iterator iter = list.iterator();

while (iter.hasNext()) {

Attribute attribute = (Attribute) iter.next();

if (attribute.getValue().equals("yes")) {

attribute.setValue("no");

}

}

/**

* 修改内容之二: 把owner项内容改为"测试修改"

* 并在owner节点中加入date节点,date节点的内容为2004-09-11,还为date节点新增一个属性type

*/

list = document.selectNodes("/books/owner");

iter = list.iterator();

if (iter.hasNext()) {

Element ownerElement = (Element) iter.next();

ownerElement.setText("测试修改");

Element dateElement = ownerElement.addElement("date");

dateElement.setText("2008-09-11");

dateElement.addAttribute("type", "日期");

}

/** 修改内容之三: 若title内容为Dom4j Tutorials,则删除该节点 */

list = document.selectNodes("/books/book");

iter = list.iterator();

while (iter.hasNext()) {

Element bookElement = (Element) iter.next();

Iterator iterator = bookElement.elementIterator("title");

while (iterator.hasNext()) {

Element titleElement = (Element) iterator.next();

if (titleElement.getText().equals("Dom4j Tutorials")) {

bookElement.remove(titleElement);

}

}

}

try {

/** 格式化输出,型别IE浏览一样 */

OutputFormat format = OutputFormat.createPrettyPrint();

/** 指定XML编码 */

format.setEncoding("GBK");

/** 将document中的内容写入档案中 */

XMLWriter writer = new XMLWriter(new FileWriter(new

File(newfilename)),format);

保证编码为UTF-8,支援中文写入

XMLWriter writer = new XMLWriter(new FileOutputStream(new File(

newfilename)), format);

writer.write(document);

writer.flush();

writer.close();

/** 执行成功,需返回1 */

returnValue = 1;

} catch (Exception ex) {

returnValue = 0;

ex.printStackTrace();

}

} catch (Exception ex) {

ex.printStackTrace();

}

return returnValue;

}

/**

* 格式化XML文件,并解决中文问题

*

* @param filename

* @return

*/

public static int formatXMLFile(String filename) {

int returnValue = 0;

try {

SAXReader saxReader = new SAXReader();

Document document = saxReader.read(new File(filename));

XMLWriter writer = null;

/** 格式化输出,型别IE浏览一样 */

OutputFormat format = OutputFormat.createPrettyPrint();

/** 指定XML编码 */

format.setEncoding("utf-8");

writer = new XMLWriter(new FileWriter(new File(filename)), format);

writer.write(document);

writer.flush();

writer.close();

/** 执行成功,需返回1 */

returnValue = 1;

} catch (Exception ex) {

returnValue = 0;

ex.printStackTrace();

}

return returnValue;

}

}

这个希望对你有用。。

java生产xml时如何指定xml的编码格式 下面是我生成xml文件的代码 while(rs.next()) { Element childElemen

//输出XML流

private void outputXML() throws DTreeException {

DOMSource domSource = new DOMSource (doc);

StreamResult streamResult = new StreamResult(this.out);

try {

TransformerFactory transformerFactory=TransformerFactory.newInstance();

Transformer transformer=transformerFactory.newTransformer();

Properties properties = transformer.getOutputProperties();

properties.setProperty(OutputKeys.ENCODING, "gb2312 ");

properties.setProperty(OutputKeys.VERSION, "1.0 ");

transformer.setOutputProperties(properties);

transformer.transform(domSource,streamResult);

}

catch (TransformerConfigurationException tce) {

tce.printStackTrace();

throw new DTreeException( "TransformerConfigure Exception: "+tce.getMessage());

}

catch (TransformerException te) {

te.printStackTrace ();

throw new DTreeException( "Transformer Exception: "+te.getMessage());

}

}


分享题目:javaxml生成代码 java jxl生成excel
网站链接:http://6mz.cn/article/hhphhc.html

其他资讯