当前位置: 技术问答>java相关
生成XML的问题
来源: 互联网 发布时间:2015-02-07
本文导语: 我要把一个表的内容生成一个XML DOM , 一行一个节点,列值放在属性里; 然后保存后文件。 谁能给个例子? 用JAXP和JSP. | 呵呵,当然可以了,你要求保存文件吧? 算了,贴你一个class好了...
我要把一个表的内容生成一个XML DOM , 一行一个节点,列值放在属性里;
然后保存后文件。
谁能给个例子?
用JAXP和JSP.
然后保存后文件。
谁能给个例子?
用JAXP和JSP.
|
呵呵,当然可以了,你要求保存文件吧?
算了,贴你一个class好了,你可以参照一下。(不过这只是我的一各demo)
package utility;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import java.io.*;
/**
* Insert the type's description here.
* Creation date: (2001-8-31 15:21:04)
* @author: Administrator
*/
public class XmlManager {
private static org.w3c.dom.Document document;
/**
* XmlManager constructor comment.
*/
public XmlManager()
{
super();
fileName = "map.xml";
loadFile(fileName);
}
/**
* Insert the method's description here.
* Creation date: (2001-9-1 11:49:29)
*/
public void addMethod()
{
try
{
Element cityElem = document.createElement("AllElement");
Element childElem = document.createElement("Element");
childElem.appendChild(document.createTextNode("TextNode"));
cityElem.appendChild(childElem);
NodeList nodeList = document.getElementsByTagName("city");
nodeList.item(0).appendChild(cityElem);
saveFile(document, "map.xml");
}
catch (Exception e)
{
System.out.println(e);
}
}
/**
* Insert the method's description here.
* Creation date: (2001-9-1 9:58:46)
* @return org.w3c.dom.Document
*/
public static org.w3c.dom.Document getDocument() {
return document;
}
/**
* Insert the method's description here.
* Creation date: (2001-8-31 16:07:12)
* @return int
*/
public int getInfo()
{
NodeList nodeList = document.getElementsByTagName("city");
for (int i = 0; i
算了,贴你一个class好了,你可以参照一下。(不过这只是我的一各demo)
package utility;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import java.io.*;
/**
* Insert the type's description here.
* Creation date: (2001-8-31 15:21:04)
* @author: Administrator
*/
public class XmlManager {
private static org.w3c.dom.Document document;
/**
* XmlManager constructor comment.
*/
public XmlManager()
{
super();
fileName = "map.xml";
loadFile(fileName);
}
/**
* Insert the method's description here.
* Creation date: (2001-9-1 11:49:29)
*/
public void addMethod()
{
try
{
Element cityElem = document.createElement("AllElement");
Element childElem = document.createElement("Element");
childElem.appendChild(document.createTextNode("TextNode"));
cityElem.appendChild(childElem);
NodeList nodeList = document.getElementsByTagName("city");
nodeList.item(0).appendChild(cityElem);
saveFile(document, "map.xml");
}
catch (Exception e)
{
System.out.println(e);
}
}
/**
* Insert the method's description here.
* Creation date: (2001-9-1 9:58:46)
* @return org.w3c.dom.Document
*/
public static org.w3c.dom.Document getDocument() {
return document;
}
/**
* Insert the method's description here.
* Creation date: (2001-8-31 16:07:12)
* @return int
*/
public int getInfo()
{
NodeList nodeList = document.getElementsByTagName("city");
for (int i = 0; i