stylesheet怎么加我也不清楚。至于导出,目前很多数据库产商都提供了XDK。
我用的是Oracle的XDK,它也支持其它数据库的,如MySQL等。
可以直接导出XML,也可以用XML插入DB记录。
去下一个吧,里面有文档的。
我用的是Oracle的XDK,它也支持其它数据库的,如MySQL等。
可以直接导出XML,也可以用XML插入DB记录。
去下一个吧,里面有文档的。
解决方案 »
- java调用dos命令
- java程序报了几个错,大伙来看看
- Sqlserver 别名查询
- 解析XML是遇到了非法字符串,郁闷死我了!!!!!!
- MQ问题!
- 求一个完整的STRUTS增删改查分页源码
- jbuilderx tomcat5 运行一下TOMCAT5没有启动起来,很短时间就终止了。
- 有没有研究Liferay Enterprise Portal的啊?
- jbuilder9+weblogic7配置后 jbuilder的new菜单下的web和enterprise标签下的东东怎么还是灰的
- 广州,深圳,上海,北京的各位程序员,有一消息大家可以看看,找工作时不要再上当!
- 使用dom对象时发生的错误!
- SAX解析根结点问题(附上通俗易懂的代码)
use
select * from table FOR XML RAWxmlDoc.createProcessingInstruction("xml:stylesheet", "type=\"text/xsl\" href=\"simple.xsl\"")
import org.jdom.input.*;
import org.jdom.output.*;
import java.io.*;public class TestXml {
public TestXml() {
} public void save(){
try {
Element element = new Element("all-item");
Comment comment = new Comment("asdAsdasdasd");
Document doc = new Document(null);
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet", "href=\"bookList.html.xsl\" type=\"text/xsl\"");
doc.addContent(pi);
doc.setRootElement(element);
Element childItem = new Element("item");
Element itemChildTopic = new Element("topic");
Element itemChildContent = new Element("content");
childItem.addContent(itemChildTopic);
childItem.addContent(itemChildContent);
element.addContent(childItem);
OutputStream out = new FileOutputStream("d:/asdfgh.xml");
XMLOutputter outp = new XMLOutputter("", true, "GBK");
outp.output(doc, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestXml testXml = new TestXml();
testXml.save();
}}
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import java.io.*;public class TestXml {
public TestXml() {
} public void save(){
try {
Element element = new Element("all-item");
Comment comment = new Comment("asdAsdasdasd");
Document doc = new Document(null);
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet", "href=\"bookList.html.xsl\" type=\"text/xsl\"");
doc.addContent(pi);
doc.setRootElement(element);
Element childItem = new Element("item");
Element itemChildTopic = new Element("topic");
Element itemChildContent = new Element("content");
childItem.addContent(itemChildTopic);
childItem.addContent(itemChildContent);
element.addContent(childItem);
OutputStream out = new FileOutputStream("d:/asdfgh.xml");
XMLOutputter outp = new XMLOutputter("", true, "GBK");
outp.output(doc, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestXml testXml = new TestXml();
testXml.save();
}}这是结果
<?xml version="1.0" encoding="GBK"?>
<?xml-stylesheet href="bookList.html.xsl" type="text/xsl"?>
<all-item>
<item>
<topic />
<content />
</item>
</all-item>
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import org.apache.xml.serialize.*;
import java.io.*;
public class SimpleXMLData{
public static final String JDBCURL="jdbc:odbc:yang";
public static String JDBCRIVER="sun.jdbc.odbc.JdbcOdbcDriver";
public static final String SQL="SELECT * FROM Customer";
public static final String OUTPUTFILE="Customer.xml";
public static void main(String args[]){
try{
Class.forName(JDBCRIVER).newInstance();
Connection conn=DriverManager.getConnection(JDBCURL);
Statement statement=conn.createStatement();
ResultSet customerRs=statement.executeQuery(SQL);
Document xmlDoc=buildCustomerXML(customerRs);
File outputFile=new File(Customer.xml);
printDOM(xmlDoc,outputFile);
conn.close(); }catch(Exception e){
System.out.println("Really Poor exception handling:"+e.toString());
}
}
private static Document buildCustomerXML(ResultSet _customerRs)
throws Exception{
Document xmlDoc=new DocumentImpl();
Element rootElement=xmlDoc.createElement("Customer");
xmlDoc.appendChild(rootElement);
while(_customerRs.next()){
Element customer=xmlDoc.createElement("Customer");
customer.setAttribute("CustomerID",_customerRs.getString("CustomerID"));
Element firstName=xmlDoc.createElement("CustomerName");
Element lastName=xmlDoc.createElement("CustomerAddress");
firstName.appendChild(xmlDoc.createTextNode(
_customerRs.getString("CustomerName")));
lastName.appendChild(xmlDoc.createTextNode(
_customerRs.getString("CustomerAddress")));
customer.appendChild(firstName);
customer.appendChild(lastName);
rootElement.appendChild(customer);
}
return xmlDoc;
}
private static void printDOM(Document _xmlDoc,File _outputFile)
throws Exception{
OutputFormat outputFormat=new OutputFormat("XML","UTF-8",true);
FileWriter fileWriter=new FileWriter(_outputFile);
XMLSerializer xmlSerializer=new XMLSerializer(
fileWriter,outputFormat);
xmlSerializer.asDOMSerializer();
xmlSerializer.serialize(_xmlDoc.getDocumentElement());
}
}
[CustomerID] [nchar ](5) COLLATE Chinese_PRC_CI_AS NOT NULL ,
CompanyName [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[CustomerAddress] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[ContactTitle] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[Address] [nvarchar] (60) COLLATE Chinese_PRC_CI_AS NULL ,
[City] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
[Region] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
[PostalCode] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[Country] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
[Phone] [nvarchar] (24) COLLATE Chinese_PRC_CI_AS NULL ,
[Fax] [nvarchar] (24) COLLATE Chinese_PRC_CI_AS NULL
)