VB.NET修改替换xml文件中的值 50
新手想用VB.NET修改替换D盘下life.xml文件中的值,把“确定”替换为“查询”life.xml-------------------<?xmlversion="1...
新手 想用VB.NET修改替换D盘下life.xml文件中的值,把“确定”替换为“查询”
life.xml
-------------------
<?xml version="1.0" encoding="utf-8" ?>
<UITranslations>
<UITranslation ID="A1" Name="zh-CN">
<Trans Original="B1" Translation="新建"/>
<Trans Original="B2" Translation="修改"/>
<Trans Original="B3" Translation="删除"/>
<Trans Original="B4" Translation="确认"/>
</UITranslation>
</UITranslations>
-------------------------------------------------
求段VB.NET代码!多谢! 展开
life.xml
-------------------
<?xml version="1.0" encoding="utf-8" ?>
<UITranslations>
<UITranslation ID="A1" Name="zh-CN">
<Trans Original="B1" Translation="新建"/>
<Trans Original="B2" Translation="修改"/>
<Trans Original="B3" Translation="删除"/>
<Trans Original="B4" Translation="确认"/>
</UITranslation>
</UITranslations>
-------------------------------------------------
求段VB.NET代码!多谢! 展开
3个回答
展开全部
Dim path As String = PDA_PATH & "ife.XML" ’PDA_PATH 为路径
Dim ds As New DataSet
ds.ReadXml(path)
Dim dt As DataTable = ds.Tables.Item(0)
Dim blnY As Boolean = True
For Each row As DataRow In dt.Rows
If row.Item("Translation").ToString.ToUpper ="确认"Then
row.Item("Translation") =“替换”
blnY = False
Exit For
End If
Next
If blnY Then
MsgBox("输入的XXX不存在,请重新输入! ")
Return
End If
ds.WriteXml(path)
MessageBox.Show("修改数据并保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
或者
Dim xmlDoc As New XmlDocument()
'Dim nodeList As New XmlNodeList
xmlDoc.Load("life..xml") '加载
Dim nodeList As XmlNodeList = xmlDoc.SelectSingleNod.("UITranslations").ChildNodes '获取bookstore节点的所有子节点
Dim xn As XmlNode
For Each xn In nodeList '遍历所有子节点
Dim xe As XmlElement = CType(xn, XmlElement) '将子节点类型转换为XmlElement类型
Dim nls As XmlNodeList = xe.ChildNodes '继续获取xe子节点的所有子节点
Dim xn1 As XmlNode
For Each xn1 In nls '遍历
Dim xe2 As XmlElement = CType(xn1, XmlElement) '转换类型
If xe2.Name = "Translation" Then '如果找到
xe2.InnerText ="替换"则修改
'Exit For Each '找到退出来就可以了
End If
Next xn1
Next xn
xmlDoc.Save("life.xml") '保存。
MessageBox.Show("修改XML成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
看能不能帮到你!
Dim ds As New DataSet
ds.ReadXml(path)
Dim dt As DataTable = ds.Tables.Item(0)
Dim blnY As Boolean = True
For Each row As DataRow In dt.Rows
If row.Item("Translation").ToString.ToUpper ="确认"Then
row.Item("Translation") =“替换”
blnY = False
Exit For
End If
Next
If blnY Then
MsgBox("输入的XXX不存在,请重新输入! ")
Return
End If
ds.WriteXml(path)
MessageBox.Show("修改数据并保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
或者
Dim xmlDoc As New XmlDocument()
'Dim nodeList As New XmlNodeList
xmlDoc.Load("life..xml") '加载
Dim nodeList As XmlNodeList = xmlDoc.SelectSingleNod.("UITranslations").ChildNodes '获取bookstore节点的所有子节点
Dim xn As XmlNode
For Each xn In nodeList '遍历所有子节点
Dim xe As XmlElement = CType(xn, XmlElement) '将子节点类型转换为XmlElement类型
Dim nls As XmlNodeList = xe.ChildNodes '继续获取xe子节点的所有子节点
Dim xn1 As XmlNode
For Each xn1 In nls '遍历
Dim xe2 As XmlElement = CType(xn1, XmlElement) '转换类型
If xe2.Name = "Translation" Then '如果找到
xe2.InnerText ="替换"则修改
'Exit For Each '找到退出来就可以了
End If
Next xn1
Next xn
xmlDoc.Save("life.xml") '保存。
MessageBox.Show("修改XML成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
看能不能帮到你!
展开全部
用ConfigurationManager就可以了
追问
请给详细说下吧!
追答
msdn搜索一下,很多,也可以百度一下 ConfigurationManager
http://social.technet.microsoft.com/search/zh-cn?query=ConfigurationManager&refinement=9&x=2&y=16
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-03-14
展开全部
你是说替换字符串吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询