create XML

string line1 = "44";
string fas01 = "4";
string jj1 = "1路车发案4起,3月1日1起";

string line2 = "43";
string fas02 = "6";
string jj2 = "6路车发案4起,3月1日1起";

XmlDocument doc = new XmlDocument();
//创建XML声明部分
XmlDeclaration Declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(Declaration, doc.DocumentElement);
//创建根节点
XmlElement Root = doc.CreateElement("Root");//主内容
doc.AppendChild(Root);

XmlElement Child1 = doc.CreateElement("luduan");

XmlAttribute attr1 = doc.CreateAttribute("mingcheng");
attr1.Value = line1;
Child1.Attributes.Append(attr1);

XmlElement fas1 = doc.CreateElement("fas");
fas1.InnerText = fas01;
Child1.AppendChild(fas1);

XmlElement jianjie = doc.CreateElement("jianjie");
jianjie.InnerText = jj1;
Child1.AppendChild(jianjie);

Root.AppendChild(Child1);

Child1 = doc.CreateElement("luduan");
attr1 = doc.CreateAttribute("mingcheng");
attr1.Value = line2;
Child1.Attributes.Append(attr1);

fas1 = doc.CreateElement("fas");
fas1.InnerText = fas02;
Child1.AppendChild(fas1);

jianjie = doc.CreateElement("jianjie");
jianjie.InnerText = jj2;
Child1.AppendChild(jianjie);

Root.AppendChild(Child1);

string path = Server.MapPath("~");
string fullpath = path + "\\Save\\" + "1.xml";
doc.Save(fullpath);

string xmlFileName = Server.MapPath("Save/1.xml");

//
StreamReader sr = new StreamReader(xmlFileName, System.Text.Encoding.Default);

string xmlData = sr.ReadToEnd();

XmlDocument doc2 = new XmlDocument();
doc2.LoadXml(xmlData);
//
doc2.Save("C://2.XML");

时间: 2024-08-30 13:44:47

create XML的相关文章

Read and Create XML

Xml makes it easy to read and write data in any application. That's enables data exchange between XML quickly became the only common language. This chapter mainly on using Xml with C#,for reading and creating XML. 1.XML basic format <?xml version="

How to create XML validator(验证器;验证程序) from XML schema

In order to check XML data for validity we have to prepare its schema XSD-file. This file will be loaded by a JAXP package to a Schema objects instance. Then we'll use Schema to produce Validator which can then be used to validate any document with t

LinqToXml (一) Create Xml file By Dom /Linq

目前,在xml 应用编程领域比较流行的开发模型是W3C 提供的DOM(文档对象模型),在.net Framework 通过命名空间 System.Xml 对该技术提供了支持.随着Linq to XMl 的诞生, .net 3.5 之后,我们可以使用Linq to sql 操作XMl .以下是通过两种方式创建相同结构的xml文件. 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using Sys

[转]SQL - Create XML - How to set Unicode UTF-8

本文转自:https://stackoverflow.com/questions/44754356/sql-create-xml-how-to-set-unicode-utf-8 I found a solution via another way. (don't remember which website I found it) See code below. This code will export my file in UTF-8-BOM encoding. DECLARE @OLE

XML 在SQLServer中的使用

SQL Server对于XML支持的核心在于XML数据的格式,这种数据类型可以将XML的数据存储于数据库的对象中,比如variables, columns, and parameters.当你用XML数据类型配置这些对象中的一个时,你指定类型的名字就像你在SQLServer 中指定一个类型一样. XML的数据类型确保了你的XML数据被完好的构建保存,同时也符合ISO的标准.在定义一个XML数据类型之前,我们首先要知道它的几种限制,如下: 一个实例的XML列不能包含超过2GB的数据. 一个XML的

(转)Unity 导出XML配置文件,动态加载场景

参考:http://www.xuanyusong.com/archives/1919 http://www.omuying.com/article/48.aspx 主要功能: 1.导出场景的配置文件 2.导出当前场景中资源的AssetBundle 3.客户端从服务器获取配置文件 4.解析配置文件,并根据配置文件下载AssetBundle 5.实例化并还原场景 1.场景设置:将需要导出的场景资源设置为预设 2.将场景配置导出为XML文件 [code]csharpcode: using UnityE

11.C#操作XML

1..NET对读写XML文件的支持 (1)System.Xml命名空间 System.Xml命名空间为处理XML提供基于标准的支持,其中提供了许多管理XML文档和XML流方式的类,还提供了一些类(例如XmlDataDocument)则是提供了XML数据存储器和存储在DataSet中的关系数据之间的桥梁. 以下是System.Xml命名空间读写XML较重要的类: XmlReader       表示提供XM数据进行快速.非缓存.只进访问的读取器. XmlWriter       提供一种快速.非缓

CMarkUp读写XML(转)

Fast start to XML in C++ Enough bull. You want to create XML or read and find things in XML. All you need to know about CMarkup is that it is just one object per XML document (for the API design concept see EDOM). And by the way the free firstobject

SQL Server 对XML数据类型的SQL语句总结

--创建XMLTable create table XMLTable(Id int IDENTITY (1, 1) primary key, XMLCol xml); go ---------------------------------------------------------------------------------- --插入XML数据单条 insert into [XML].[dbo].[XMLTable] ([XMLCol]) select * from openrows