会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
SAP & ASP.NET
XML的读写
/**/
///
<summary>
///
从已有的XML文件读取
///
</summary>
private
void
ReadXml()
...
{
XmlDocument xmlDoc
=
new
XmlDocument();
xmlDoc.Load(Server.MapPath(
"
EnterpriseIntroduce.xml
"
));
//
XmlNode xmlDocSelect = xmlDoc.SelectSingleNode("Introduce");
XmlNodeReader nodeRd
=
new
XmlNodeReader(xmlDoc);
while
(nodeRd.Read())
...
{
if
(nodeRd.NodeType
==
XmlNodeType.Element)
...
{
switch
(nodeRd.Name)
...
{
case
"
Name
"
:
nodeRd.Read();
this
.txtName.Text
=
nodeRd.Value;
break
;
case
"
Webset
"
:
nodeRd.Read();
this
.txtWebset.Text
=
nodeRd.Value;
break
;
case
"
Phone
"
:
nodeRd.Read();
this
.txtPhone.Text
=
nodeRd.Value;
break
;
case
"
Address
"
:
nodeRd.Read();
this
.txtAddress.Text
=
nodeRd.Value;
break
;
case
"
IntroduceText
"
:
nodeRd.Read();
this
.txtIntroduce.Text
=
nodeRd.Value;
break
;
default
:
break
;
}
}
}
}
/**/
///
<summary>
///
将页面信息存入到指定的XML文件中
///
</summary>
private
void
WriteXmlFromTxt()
...
{
XmlDocument xmlDoc
=
new
XmlDocument();
xmlDoc.Load(Server.MapPath(
"
EnterpriseIntroduce.xml
"
));
XmlNode xmlDocSelect
=
xmlDoc.SelectSingleNode(
"
Introduce
"
);
XmlNodeList nodeList
=
xmlDoc.SelectSingleNode(
"
Introduce
"
).ChildNodes;
if
(nodeList.Count
==
0
)
...
{
XmlElement xmlEl
=
xmlDoc.CreateElement(
"
Name
"
);
//
添加Name节点存放公司名称
xmlEl.InnerText
=
this
.txtName.Text.ToString().Trim();
xmlDocSelect.AppendChild(xmlEl);
xmlEl
=
xmlDoc.CreateElement(
"
Webset
"
);
//
添加Name节点存放公司名称
xmlEl.InnerText
=
this
.txtWebset.Text.ToString().Trim();
xmlDocSelect.AppendChild(xmlEl);
xmlEl
=
xmlDoc.CreateElement(
"
Phone
"
);
//
添加Name节点存放公司名称
xmlEl.InnerText
=
this
.txtPhone.Text.ToString().Trim();
xmlDocSelect.AppendChild(xmlEl);
xmlEl
=
xmlDoc.CreateElement(
"
Address
"
);
//
添加Name节点存放公司名称
xmlEl.InnerText
=
this
.txtAddress.Text.ToString().Trim();
xmlDocSelect.AppendChild(xmlEl);
xmlEl
=
xmlDoc.CreateElement(
"
IntroduceText
"
);
//
添加Name节点存放公司名称
xmlEl.InnerText
=
this
.txtIntroduce.Text.ToString().Trim();
xmlDocSelect.AppendChild(xmlEl);
}
else
...
{
foreach
(XmlNode xn
in
nodeList)
//
遍历所有子节点
...
{
XmlElement xeTmp
=
(XmlElement)xn;
if
(xeTmp.Name
==
"
Name
"
)
...
{
xeTmp.InnerText
=
this
.txtName.Text.ToString();
continue
;
}
if
(xeTmp.Name
==
"
Webset
"
)
...
{
xeTmp.InnerText
=
this
.txtWebset.Text.ToString();
continue
;
}
if
(xeTmp.Name
==
"
Phone
"
)
...
{
xeTmp.InnerText
=
this
.txtPhone.Text.ToString();
continue
;
}
if
(xeTmp.Name
==
"
Address
"
)
...
{
xeTmp.InnerText
=
this
.txtAddress.Text.ToString();
continue
;
}
if
(xeTmp.Name
==
"
IntroduceText
"
)
...
{
xeTmp.InnerText
=
this
.txtIntroduce.Text.ToString();
continue
;
}
}
}
xmlDoc.Save(Server.MapPath(
"
EnterpriseIntroduce.xml
"
));
}
posted on
2007-10-19 10:51
LongSky
阅读(
130
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
新随笔
订阅
管理
公告