zoukankan
html css js c++ java
在asp.net添加数据到XML里去
xml 文件内容如下:
<?
xml version="1.0" encoding="utf-8"
?>
<
bookstore
>
<
book
genre
="fantasy"
ISBN
="4-2341-8"
>
<
title
>
C#编程指南
</
title
>
<
author
>
James Zhao aaa
</
author
>
<
price
>
53.95
</
price
>
</
book
>
<
book
genre
="计算机"
ISBN
="4-12344-8"
>
<
title
>
C#入门经典
</
title
>
<
author
>
不知道
</
author
>
<
price
>
20$
</
price
>
</
book
>
<
book
genre
="xiaotuni"
ISBN
="2-3342-8"
>
<
title
>
C#高级编程
</
title
>
<
author
>
LHB
</
author
>
<
price
>
13$
</
price
>
</
book
>
<
book
genre
="asp.net"
ISBN
="7-302-05407-x"
>
<
title
>
ASP.NET入门经典
</
title
>
<
author
>
Chris Ullman、Chirs Goode and so on
</
author
>
<
price
>
75元
</
price
>
</
book
>
<
book
genre
="廖海兵"
ISBN
="JX-XY-1984-03-08"
>
<
title
>
我的生日
</
title
>
<
author
>
xiaotuni
</
author
>
<
price
>
21
</
price
>
</
book
>
<
book
genre
="a"
ISBN
="b"
>
<
title
>
c
</
title
>
<
author
>
d
</
author
>
<
price
>
e
</
price
>
</
book
>
<
book
genre
="aa"
ISBN
="BB-CC-DD-EE-FF"
>
<
title
>
goole Cools
</
title
>
<
author
>
不明
</
author
>
<
price
>
20元
</
price
>
</
book
>
<
book
genre
="b"
ISBN
="BB-E-1234-JX"
>
<
title
>
KSIK
</
title
>
<
author
>
LASERF
</
author
>
<
price
>
20元
</
price
>
</
book
>
<
book
genre
="www"
ISBN
="baidu"
>
<
title
>
com
</
title
>
<
author
>
1234
</
author
>
<
price
>
21
</
price
>
</
book
>
</
bookstore
>
/**/
///
<summary>
///
添加数据到Xml里去
///
</summary>
///
<param name="Gener">
类型
</param>
///
<param name="isbn">
图书编号
</param>
///
<param name="Author">
作者
</param>
///
<param name="Title">
图书标题
</param>
///
<param name="Price">
价格
</param>
private
bool
AddDate(
string
Genre,
string
isbn,
string
Author,
string
Title,
string
Price)
...
{
bool
addXmlDate
=
false
;
//
返回是不是要添加数据
int
ChunZai
=
0
;
//
记录是不是存在
int
BuChunZai
=
0
;
//
记录是不是不存在
XmlDocument xmlDoc
=
new
XmlDocument();
xmlDoc.Load(Server.MapPath(
"
BookStore.xml
"
));
//
把XML文件装载进来
//
把有的BookStore节点的所有子节点拿出来
XmlNodeList nodeList
=
xmlDoc.SelectSingleNode(
"
bookstore
"
).ChildNodes;
//
遍历第一级所有子节点
foreach
(XmlNode xn
in
nodeList)
...
{
//
XmlElement xe
=
(XmlElement)xn;
if
(xe.GetAttribute(
"
genre
"
)
==
Genre)
//
说明此已经存在
...
{
ChunZai
++
;
break
;
}
else
...
{
BuChunZai
++
;
if
(BuChunZai
==
nodeList.Count)
...
{
break
;
}
}
}
if
(ChunZai
==
0
)
//
如果存在为0那么说明此xml文件里没有此数据可以添加
...
{
XmlNode root
=
xmlDoc.SelectSingleNode(
"
bookstore
"
);
XmlElement xel
=
xmlDoc.CreateElement(
"
book
"
);
xel.SetAttribute(
"
genre
"
, Genre);
//
设置该节点的ISBN属性
xel.SetAttribute(
"
ISBN
"
, isbn);
//
设置本节点为书的标题
XmlElement xesubTitle
=
xmlDoc.CreateElement(
"
title
"
);
xesubTitle.InnerText
=
Title;
xel.AppendChild(xesubTitle);
//
书作者
XmlElement xesubAuthor
=
xmlDoc.CreateElement(
"
author
"
);
xesubAuthor.InnerText
=
Author;
xel.AppendChild(xesubAuthor);
//
书价格
XmlElement xesubPrice
=
xmlDoc.CreateElement(
"
price
"
);
xesubPrice.InnerText
=
Price;
xel.AppendChild(xesubPrice);
//
添加到 bookStore 的root里去
root.AppendChild(xel);
xmlDoc.Save(Server.MapPath(
"
BookStore.xml
"
));
//
保存添加的数据
addXmlDate
=
true
;
}
else
...
{
addXmlDate
=
false
;
//
说明要添加的数据已经存在,
}
return
addXmlDate;
}
那个html里的代码就不知道怎么弄,好几个月了,代码不知道放到哪里去了
查看全文
相关阅读:
Zabbix——1
Hive 基础知识——01
Vim快捷命令
Shell——2
Shell——6
Shell——4
Shell——3
Shell——1
Hive 安装和配置以及基本语法——02
Shell——5
原文地址:https://www.cnblogs.com/xiaotuni/p/2365806.html
最新文章
POJ 2922 Honeymoon Hike 解题报告(二分+深搜)
string用法
操作系统中的概念解释
cmd下制作U盘启动盘命令
Ubuntu下安装JDK
Android UI – 控件和布局
让Vim更好用 for Mac OS X | Hessian's Blog
The ZIndex CSS Property: A Comprehensive Look | Smashing Coding
jquery dynamic dictionary using javascript Stack Overflow
Yann's Blog » Using Facebook’s Thrift with Python and HBase
热门文章
gmarik/vundle · GitHub
Json values in jQuery foreach loop Stack Overflow
jQuery.extend() | jQuery API Documentation
5 jQuery.each() Function Examples | jQuery4u
Iterating over jQuery and nonjQuery Objects | jQuery Learning Center
从团购网的漏洞看网站安全性问题 安全 IT技术博客大学习 共学习 共进步!
Occlusion Aware Facial Expression Recognition Using CNN With Attention Mechanism(2019 TIP)
MAML算法理解
Edgeaware Graph Representation Learning and Reasoning for Face Parsing(2020 ECCV)
想找个合适的地方贴东西,找了好几个,不知道选谁好,于是注册breeze这个用户名
Copyright © 2011-2022 走看看