创建指定的xml文档二
2008-12-07 18:31
120 查看
指定XML格式为
<班级>
<学生 学号="0443111241" 姓名="张三">
<成绩 语文="88" 数学="99" 英语="100" />
</学生>
<学生 学号="0443111121" 姓名="李四">
<成绩 语文="92" 数学="90" 英语="96" />
</学生>
</班级>
public string xmlCreate()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<班级></班级>");
XmlNode newNode =doc.CreateNode("element","学生","");
XmlNode root = doc.DocumentElement;
root.AppendChild(newNode);
XmlAttribute newAttribute = doc.CreateAttribute("学号");
newAttribute.Value = "0443111241";
newNode.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("姓名");
newAttribute.Value = "张三";
newNode.Attributes.Append(newAttribute);
XmlNode newNode1 = doc.CreateNode("element", "成绩", "");
newNode.AppendChild(newNode1);
newAttribute = doc.CreateAttribute("语文");
newAttribute.Value = "88";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("数学");
newAttribute.Value = "99";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("英语");
newAttribute.Value = "100";
newNode1.Attributes.Append(newAttribute);
newNode = doc.CreateNode("element", "学生", "");
root.AppendChild(newNode);
newAttribute = doc.CreateAttribute("学号");
newAttribute.Value = "0443111121";
newNode.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("姓名");
newAttribute.Value = "李四";
newNode.Attributes.Append(newAttribute);
newNode1 = doc.CreateNode("element", "成绩", "");
newNode.AppendChild(newNode1);
newAttribute = doc.CreateAttribute("语文");
newAttribute.Value = "92";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("数学");
newAttribute.Value = "90";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("英语");
newAttribute.Value = "96";
newNode1.Attributes.Append(newAttribute);
return doc.OuterXml;
}
<班级>
<学生 学号="0443111241" 姓名="张三">
<成绩 语文="88" 数学="99" 英语="100" />
</学生>
<学生 学号="0443111121" 姓名="李四">
<成绩 语文="92" 数学="90" 英语="96" />
</学生>
</班级>
public string xmlCreate()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<班级></班级>");
XmlNode newNode =doc.CreateNode("element","学生","");
XmlNode root = doc.DocumentElement;
root.AppendChild(newNode);
XmlAttribute newAttribute = doc.CreateAttribute("学号");
newAttribute.Value = "0443111241";
newNode.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("姓名");
newAttribute.Value = "张三";
newNode.Attributes.Append(newAttribute);
XmlNode newNode1 = doc.CreateNode("element", "成绩", "");
newNode.AppendChild(newNode1);
newAttribute = doc.CreateAttribute("语文");
newAttribute.Value = "88";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("数学");
newAttribute.Value = "99";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("英语");
newAttribute.Value = "100";
newNode1.Attributes.Append(newAttribute);
newNode = doc.CreateNode("element", "学生", "");
root.AppendChild(newNode);
newAttribute = doc.CreateAttribute("学号");
newAttribute.Value = "0443111121";
newNode.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("姓名");
newAttribute.Value = "李四";
newNode.Attributes.Append(newAttribute);
newNode1 = doc.CreateNode("element", "成绩", "");
newNode.AppendChild(newNode1);
newAttribute = doc.CreateAttribute("语文");
newAttribute.Value = "92";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("数学");
newAttribute.Value = "90";
newNode1.Attributes.Append(newAttribute);
newAttribute = doc.CreateAttribute("英语");
newAttribute.Value = "96";
newNode1.Attributes.Append(newAttribute);
return doc.OuterXml;
}
相关文章推荐
- 创建指定的xml文档一
- 创建指定的xml文档三
- asp.net使用XML创建Excel文档
- C# 创建简单XML文档
- Java的XML创建、解析文档
- OpenXml SDK 2.0 创建Word文档——最简化的版本
- 用JAVA创建XML文档,为java API文档添加搜索功能
- OpenXml To Excel之创建文档2
- C#来创建和读取XML文档
- NSIS ---使用nsDialogs创建自定义页面,并获取输入到控件中的内容保存到一个XML文档中
- WebService生成XML文档时出错。不应是类型XXXX。使用XmlInclude或SoapInclude属性静态指定非已知的类型。
- JAVA 基于dom4j创建XML文档
- JDOM入门实例:读取与创建xml文档
- JDOM入门实例:读取与创建xml文档
- 创建一个book.xml文档,PHP通过DOM方式解析获得每本书的作者和书名
- XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)
- C#来创建和读取XML文档(一)
- .NET 通过代码创建XML文档
- Java四种读取和创建XML文档的例子
- 使用dom4j创建XML文档