利用VB操作XML数据.txt
《利用VB操作XML数据.txt》由会员分享,可在线阅读,更多相关《利用VB操作XML数据.txt(10页珍藏版)》请在文库网上搜索。
1、XML XML洢XMLXML XMLAccess,OracleSQL Server洢磺XMLXMLXML XMLXMLXMLWindowsMac OS, LinuxXMLXML XML XML佻XMLINI洢INIVisual BasicINI XMLXML ASPASP.NETWEBXML XMLXMLXML洢 XML XMLXMLHTMLXML绰 Phone987-654-3210/Phone XMLPhone/Phone/phone/PHONE
2、 PhoneTypeWorkFax: Phone Type=WorkFax987-654-3210Phone PhoneNumber洢绰 Phone Type=WorkFax Number=987-654-3210 / XML Addresses Entry Type=Personal FirstNameAndy/FirstName LastNameFickle/LastName Street1234 Programmer Place/Street CityBugsville/City StateCO/State Zip82379/Zip Phone Type=Home354-493-9489
3、/Phone /Entry Entry Type=Work FirstNameBetty/FirstName LastNameMasterson/LastName Phone Type=Work937-878-4958/Phone Phone Type=WorkFax937-878-4900/Phone /Entry . /Addresses Entry绰EntryWorkWorkFax绰Entry XML XMLXMLXMLVisual BasicWindows LXMLXMLXMLXML Writer XML DOM洢XMLDOM XSDXMLXSLXMLWEBHTML
4、XMLXML鼮XML Visual Basic.NetXMLXSLXMLVB.NETXMLMSXML汾4.0Visual Basic6.0洢XML Basic 6.0Microsoft XML V4.0Microsoft V4.0,OK,VBXML DOMDocument (DOM)XMLDOMDocumentXMLDOMMSXML DOMDocumentLoadxmlloadxmlxml磬xmlxml_document Dim xml_document As New DOMDocument xml_document.loadXML _ Person & vbCrLf & _ FirstNam
5、eRod/FirstName & vbCrLf & _ LastNameStephens/LastName & vbCrLf & _ /Person DOMDocumentxmlxml洢DOMDocumentsave洢 DOMDocumentdocumentElementXML DOMDocumentCreateElementcreateAttribute, createProcessingInstruction, createTextNode IXMLDOMNode IXMLDOMNodeXML selectSingleNode XPATHXPATH淶 selectsing
6、leNode./ Search for a child node named LastName. Set last_name_node = address_node.selectSingleNode(LastName) Search for any descendant named LastName. Set last_name_node = address_node.selectSingleNode(./LastName) IXMLDOMNode attributes. nodeName. nodeTypeString. ownerDocument.DOMDocument text.text
7、 xml.xml磺FirstNameRod/FirstName. ChildNodesDOMDocumentchildNodesappendChild Add a new node to the indicated parent node. Private Sub CreateNode(ByVal indent As Integer, _ ByVal parent As IXMLDOMNode, ByVal node_name As String, _ ByVal node_value As String) Dim new_node As IXMLDOMNode Create
8、 the new node. Set new_node = parent.ownerDocument.createElement(node_name) Set the nodes text value. new_node.Text = node_value Add the node to the parent. parent.appendChild new_node End Sub SaveValues XML1洢XMLVALUE.XMLVALUE.XML VALUE.XML: Values FirstNameRod/FirstName LastNameStephens/La
9、stName Street1234 Programmer Place/Street CityBugsville/City StateCO/State Zip80276/Zip /Values List1SaveValuesform_loadLoadValues LoadValuesxml_documentDOMDocumentxmlselectSingleNodevaluesGetNodeValuevalue GetNodeValuevalueselectSingleNodeGetNodeValuetextvalue.xmltext form_unloadunloadSaveValues
10、61747;DOMDocumentvalueappendChild SaveValuesDOMDocuments save洢xml DOMDocumentXMLXML List1CreateNodeCreateNode DOMDocumentcreateElement createNodetext List1: Option Explicit Private m_AppPath As String Private Sub Form_Load() Get the applications startup
11、 path. m_AppPath = App.Path If Right$(m_AppPath, 1) Then m_AppPath = m_AppPath & Load the values. LoadValues End Sub Private Sub Form_Unload(Cancel As Integer) Save the current values. SaveValues End Sub Load saved values from XML. Private Sub LoadValues() Dim xml_document As DOMDocument Dim values_
12、node As IXMLDOMNode Load the document. Set xml_document = New DOMDocument xml_document.Load m_AppPath & Values.xml If the file doesnt exist, then xml_document.documentElement is Nothing. If xml_document.documentElement Is Nothing Then The file doesnt exist. Do nothing. Exit Sub End If Find the Value
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 利用 VB 操作 XML 数据