如何使用c#动态地在xml中创建文件 [英] how to create file in xml using c# Dynamically
本文介绍了如何使用c#动态地在xml中创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<? xml version = 1.0 编码 = < span class =code-keyword> UTF-8 ? >
< 身份验证 用户名 = testuser 密码 = ECLPASS / >
< 酒店 id = 411 / >
< AvailRateUpdate >
如何在c中创建这种类型的coad
i可以创建
< 身份验证 用户名 = testuser 密码 = ECLPASS / > 此行但添加新的noad酒店然后它可以在
之内< 身份验证 用户名 = testuser 密码 = ECLPASS >
< hotel id = < span class =code-keyword> 411 / >
< / authentication >
如何解决此
或如何创建hotelid身份验证完成后
我的代码低于
XmlTextWriter writer = new XmlTextWriter(Server.MapPath(product.xml),System.Text.Encoding.UTF8);
XmlDocument doc = new XmlDocument();
writer.WriteStartDocument(true);
writer.Formatting = Formatting.Indented;
XmlNode AuthenticationNode = doc.CreateElement(Authentication);
XmlAttribute UserName = doc.CreateAttribute(id);
UserName.Value =eqcuser;
XmlAttribute password = doc.CreateAttribute(Password);
password.Value =eqcpass;
AuthenticationNode.Attributes.Append(UserName);
AuthenticationNode.Attributes.Append(密码);
doc.AppendChild(AuthenticationNode);
XmlNode root = doc.CreateElement(Hotel);
XmlAttribute HotelNode = doc.CreateAttribute(Id);
HotelNode.Value =36972;
root.Attributes.Append(HotelNode);
doc.AppendChild(root);
解决方案
试试这个。 :)
如何用C#创建XML文件 [ ^ ]
如何在c#中以编程方式创建xml文档 [ ^ ]
用C#创建XML [ ^ ]
C#XmlWriter [ ^ ]
将DataTable转换为XML使用c# [ ^ ]
<?xml version="1.0" encoding="UTF-8"?>
<Authentication username="testuser" password="ECLPASS"/>
<Hotel id="411"/>
<AvailRateUpdate>
how to create this type of coad in c#
i can create
<Authentication username="testuser" password="ECLPASS"/> this line but add new noad hotel then it can be inside of
<authentication username="testuser" password="ECLPASS">
<hotel id="411" />
</authentication>
How to solve this
or how to create hotelid after the authentication completes
my code below
XmlTextWriter writer = new XmlTextWriter(Server.MapPath ("product.xml"), System.Text.Encoding.UTF8);
XmlDocument doc = new XmlDocument();
writer.WriteStartDocument(true);
writer.Formatting = Formatting.Indented;
XmlNode AuthenticationNode = doc.CreateElement("Authentication");
XmlAttribute UserName = doc.CreateAttribute("id");
UserName.Value = "eqcuser";
XmlAttribute password = doc.CreateAttribute("Password");
password.Value = "eqcpass";
AuthenticationNode.Attributes.Append(UserName);
AuthenticationNode.Attributes.Append(password);
doc.AppendChild(AuthenticationNode);
XmlNode root = doc.CreateElement("Hotel");
XmlAttribute HotelNode = doc.CreateAttribute("Id");
HotelNode.Value = "36972";
root.Attributes.Append(HotelNode);
doc.AppendChild(root);
解决方案
try this. :)
How to create an XML file in C#[^]
how to create xml document programatically in c#[^]
Create XML in C#[^]
C# XmlWriter[^]
Convert DataTable to XML using c#[^]
这篇关于如何使用c#动态地在xml中创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文