利用SqlHelper(ExecuteXmlReader使用),转换到xml格式
利用sqlhelper中的ExcuteXmlReader方法,读取数据并保存为xml文件
string strConn = Properties.Settings.Default.Connections;
SqlConnection connection = new SqlConnection(strConn);
---注意:后面的for格式
string strsql = "select * from p where name=@name and other=@other FOR XML AUTO,root('root'),elements";
SqlParameter[] sqlp = new SqlParameter[2];
sqlp[0] = new SqlParameter("@name", "pp");
sqlp[1] = new SqlParameter("@other", "ss");
xr = SqlHelper.ExecuteXmlReader(connection, CommandType.Text, strsql,
sqlp);
XmlDocument xml = new XmlDocument();
xml.Load(xr);
xml.Save(Application.StartupPath + "\\test1.xml");
相关文档:
//打开某文件(假设web.config在根目录中)
string filename=Server.MapPath("/") + @"WebApplication1\web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);
//得到顶层节点列表
......
有时候我门需要把EXCEL表格中的数据转换成XML格式 这需要用到JXL(分析EXCEL)包和JDOM包(构成XML)
import java.io.*;
import jxl.*;
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
/**
*
* @author guo
*/
public class EtoX {
  ......
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:S ......
Dom4J是一个开源的优秀的XML解析API,现在越来越多的项目中开始采用这种解析方式,其中包含了著名的Hibernate。这里我们使用Dom4J解析一个带命名空间的CXF的Spring配置文件。先导入dom4j-1.6.1.jar
spring 配置文件 applicationContext-cxf.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//s ......