利用Visual Basic操作XML数据,利用Visual,用VisualB,VisualBa,isualBas,sualBasi,ualBasic,alBasic操,lBasic操作,Basic操作X,asic操作XM,sic操作XML,ic操作XML数 利用Visual Basic操作XML数据----编程资料集中营--八角123--bajiao123.com
编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 进入问吧 | 
利用Visual Basic操作XML数据,什么是XML扩展标记语言XML是一种简单的数据存储语言,使用一系列简单的标记描述数据,而这些标记可以用方便的方式建立,虽然XML占用的空间比二进制数据要占用更多的空间,但XML极其简单易于掌握和使用。XML与Access,Oracle和SQLServer等数据库不同,数据库提供了更强有力的数据存储和分析能力,例如:数据索引、排序、查找、相关一致性等,XML仅,
您现在的位置: 编程资料,学习资料,c,c++,vc,vc++,java,jsp,j2ee,j2me,asp,php >> 文章中心 >> .NET 专区 >> NET 技术 >> 文章正文
【字体:
利用Visual Basic操作XML数据   进入问吧

本站地址:http://www.bajiao123.com

作者:admin    文章来源:本站    点击数:    更新时间:2007-6-10    

利用Visual Basic操作XML数据

GetNodeValue = default_value
Else
GetNodeValue = value_node.Text
End If
End Function

´ Save the current values.
Private Sub SaveValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode

´ Create the XML document.
Set xml_document = New DOMDocument

´ Create the Values section node.
Set values_node = xml_document.createElement("Values")

´ Add the Values section node to the document.
xml_document.appendChild values_node

´ Create nodes for the values inside the
´ Values section node.
CreateNode values_node, "FirstName", txtFirstName.Text
CreateNode values_node, "LastName", txtLastName.Text
CreateNode values_node, "Street", txtStreet.Text
CreateNode values_node, "City", txtCity.Text
CreateNode values_node, "State", txtState.Text
CreateNode values_node, "Zip", txtZip.Text

´ Save the XML document.
xml_document.save m_AppPath & "Values.xml"
End Sub

´ Add a new node to the indicated parent node.
Private Sub CreateNode(ByVal parent As IXMLDOMNode, _
ByVal node_name As String, ByVal node_value As String)
Dim new_node As IXMLDOMNode

´ Create the new node.
Set new_node = parent.ownerDocument.createElement(node_name)

´ Set the node´s text value.
new_node.Text = node_value

´ Add the node to the parent.
parent.appendChild new_node
End Sub SaveValuesIndented 程序

  虽然每个人都化了很大的精力去处理xml文档,使他们看上更容易些,但xml工具一般都忽略了那些使xml文档结构明显的空白和缩进,xml解析器也同样忽略缩进和空白。

  不幸的是我们例子也同样忽略了这些缩进和空白,SaveValues创建了一个象下面那样的xml文件,所有的代码都在同一行中。

<Values><FirstName>Rod</FirstName><LastName>Stephens</LastNa
me><Street>1234 Programmer Place</Street><City>Bugsville</Ci
ty><State>CO</State><Zip>80276</Zip></Values>
  VB.NET中包括了文本写入类,可以XML文档规定格式。但MSXML重没有这种功能,所以如果需要以一种清晰的格式保存XML文件,只能另行添加它的格式。

  List2列出了程序SaveValuesIndented使用的代码,SaveValues子程序与上面例子中讲的几乎完全相同,但他在创建value节点后同时给XML文档创建了一个<value>标记的新行。

  然后SaveValues 调用CreateNode创建一个新的数据节点,但在这里它传递给CreateNode一个新的参数,这个参数表示这个新节点的缩进方式。

  CreateNode

´ Save the current values.
Private Sub SaveValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode

´ Create the XML document.
Set xml_document = New DOMDocument

´ Create the Values section node.
Set values_node = xml_document.createElement("Values")

´ Add a new line.
values_node.appendChild xml_document.createTextNode(vbCrLf)

´ Add the Values section node to the document.
xml_document.appendChild values_node

´ Create nodes for the values inside the
´ Values section node.
CreateNode 4, values_nod

上一页  [1] [2] [3] [4] [5] 下一页

   

进入问吧

本站地址:http://www.bajiao123.com

文章录入:admin    责任编辑:admin 
高级搜索
编程资料集中营