C# 格式化输出XML
很多时候有一个xml字符串,没有换行,没有缩进,要生成xml文件不易阅读。下面的代码就是怎么将一个连续的xml字符串格式化输出
// a demo string
string xml = "<Root><Eles><Ele>abc</Ele><Ele>123</Ele></Eles></Root>";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);
System.IO.StringWriter sw = new System.IO.StringWriter();
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(sw))
{
writer.Indentation = 2; // the Indentation
writer.Formatting = System.Xml.Formatting.Indented;
doc.WriteContentTo(writer);
writer.Close();
}
// out put the formated xml
Console.WriteLine(sw.ToString());
相关文档:
1,在web服务器上安装Oracle数据库客户端,这是连接Oracle数据库的基础(但,不一定是必须的)。
2,在客户端的Net Manager 中进行配置服务的名称,配置如图(这一点非常的重要以后的链接全都在这个服务名称的基础上进行的)
3,ASP链接服务的链接字符串和方法如下:
<%
connstr= "Provider=MSDAORA.1;Password=***; ......
protected void BindData1()
{
OracleConnection orcn = new OracleConnection("User ID=wesoftwcp; Password=wesoft; Data Source=oradb");
orcn.Open();
&nb ......
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.comboBox2.Items.Clear();
switch(this.comboBox1.SelectedIndex)
  ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
namespace WebApplication2
{
/// <summary>
/// XMLHelper XML文档操作管理器
&nb ......
通过xsl转换大xml文件
这几天在做这个,网上的几个方法我都试过了,汇总如下
方法一:
XPathDocument myXPathDoc = new XPathDocument(tbXMLFile.Text);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(tbXSLFile.Text);
XmlTextWriter myWriter = new XmlTextWrit ......