当前位置: 代码迷 >> VC >> 有关XML格式文体的读取解决办法
  详细解决方案

有关XML格式文体的读取解决办法

热度:1518   发布时间:2013-02-25 00:00:00.0
有关XML格式文体的读取
计划用CFILE类读取XML格式文本
格式如:
<FLIE>
<xml   name= "情况1 "   value= "值1 ">
  <xml1   name= "A "   value= "A "> </xml1>
  <xml1   name= "B "   value= "B "> </xml1>
        ...
        ...
  <xml1   name= "N "   value= "N "> </xml1>
</xml1>
<xml   name= "情况2 "   value= "值2 ">
  <xml1   name= "AA "   value= "AA "> </xml1>
  <xml1   name= "BB "   value= "BB "> </xml1>
        ...
        ...
  <xmln   name= "NN "   value= "NN "> </xml1>
</xml>
</FILE>


想用CFILE类读取上述格式文本数据,
如读取:
当 <xml> 的value= "值2 "时,读取 <xml1> name= "BB "的value的值?

怎么操作?

大家知道下干怎么做,
最好上CODE

------解决方案--------------------------------------------------------
用MSXML组件

------解决方案--------------------------------------------------------
读:
Private Function CreatTables(ByVal strKeyName As String, ByVal strWhich As String) As Boolean
Dim sql As String
Dim s As String
'创建XML文档实例
Dim XMLWebSetting As System.Xml.XmlDocument = New System.Xml.XmlDocument
'打开XML文档
XMLWebSetting.Load(System.Web.HttpContext.Current.Server.MapPath( "~/ " + strWhich + " "))

'查找节点所在位置
Dim XmlNodeList As System.Xml.XmlNodeList = XMLWebSetting.SelectSingleNode( "//appSettings ").ChildNodes
Dim xn As System.Xml.XmlNode
Dim xe As System.Xml.XmlElement

For Each xn In XmlNodeList
Try
sql = xn.Attributes( "value ").InnerText
EXESQL(sql)
Catch
End Try
Next
Return True
End Function

写:
Private Sub SaveSetting(ByVal strKeyName As String, ByVal strKeyValue As String, ByVal strWhich As String)

'创建XML文档实例
Dim XMLWebSetting As System.Xml.XmlDocument = New System.Xml.XmlDocument
'打开XML文档
XMLWebSetting.Load(System.Web.HttpContext.Current.Server.MapPath( "~/ " + strWhich + " "))

'查找节点所在位置
Dim XmlNodeList As System.Xml.XmlNodeList = XMLWebSetting.SelectSingleNode( "//appSettings ").ChildNodes
Dim xn As System.Xml.XmlNode
Dim xe As System.Xml.XmlElement
Try
For Each xn In XmlNodeList
xe = CType(xn, System.Xml.XmlElement)
If xe.Attributes( "key ").InnerText = strKeyName Then
xe.Attributes( "value ").InnerText = strKeyValue
XMLWebSetting.Save(System.Web.HttpContext.Current.Server.MapPath( "~/ " + strWhich + " "))
Exit For
End If
Next
Catch
End Try
End Sub



过程使用:SaveSetting( "ConStr ", Trim(TextBox1.Text), "web.config ")

------解决方案--------------------------------------------------------
用MSXML组件, you may read the file carefully:
http://dev.yesky.com/413/2510413.shtml
  相关解决方案