In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use DOM to parse VB.NET XML files, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
XML file is safe, in the program, most of our files are XML files, but for using DOM to parse XML files skillfully or very little, how to use DOM to parse VB.NET XML files?
1, the establishment of a string to write a file, XML is composed of, in fact, all the characters are formed and then written into the file. But this kind of method is not suitable for big data's operation.
2. XLST is not suitable for CSS,VB.
3 、 DOM .
So the introduction is to use DOM to write VB.NET XML files. The following example is exemplified by the Employee table in SQLSERVER's Northwind. The VB.NET XML file code is as follows:
Option Explicit Public RsAs New ADODB.Recordset Public Conn As New ADODB.Connection Public tempDocAs MSXML2.DOMDocument 'xml file Public tempNode As MSXML2.IXMLDOMNode Public Root As MSXML2.IXMLDOMElement Public tempelement As MSXML2.IXMLDOMElement Public tempattribute As MSXML2.IXMLDOMElement Public emp As MSXML2.IXMLDOMElement Private Sub Command1_Click ()' generates a XML DOMDocument object Set tempDoc = New MSXML2.DOMDocument 'generates the root node and sets it as the root of the file Set Root = tempDoc.createElement ("employees") Set tempDoc.documentElement = Root 'add multiple attributes Call Root.setAttribute ("xmlns:xsd") on the node "http://www.w3.org/2001/XMLSchema") Call Root.setAttribute (" xmlns:xsi "," http://www.w3.org/2001/XMLSchema-instance") Call Root.setAttribute ("xmlns", "http://www.kingdee.com/ReK3Inventory") Do While Not Rs.EOF Set emp = tempDoc.createNode (MSXML2.NODE_ELEMENT," employee ",") Root.appendChild emp 'generate child node and add it to the root node And set an attribute Set tempNode = tempDoc.createNode (MSXML2.NODE_ELEMENT, "Employeeid", "") tempNode.Text = Rs (0) emp.appendChild tempNode Set tempNode = tempDoc.createNode (MSXML2.NODE_ELEMENT, "Firstname", "") tempNode.Text = Rs (1) emp.appendChild tempNode Set tempNode = tempDoc.createNode (MSXML2.NODE_ELEMENT, "Title") for this node "") tempNode.Text = Rs (2) emp.appendChild tempNode Rs.MoveNext Loop Dim pi As IXMLDOMProcessingInstruction Set pi = tempDoc.createProcessingInstruction ("xml", "version='1.0' encoding='gb2312'") Call tempDoc.insertBefore (pi TempDoc.childNodes (0) 'can be saved directly as a file to tempDoc.Save "c:\ myTest.xml" Unload Me End Sub Private Sub Form_Load ()' and connect SQLSERVER Dim strConn As String strConn = "Provider=SQLOLEDB.1" Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=LocalHost "Conn.CursorLocation = adUseClient Conn.Open strConn If Rs.State adStateClosed Then Rs.Close Rs.Open" Select employeeid,Firstname,Title from employees ", Conn, adOpenStatic, adLockOptimistic End Sub Private Sub Form_Unload (Cancel As Integer) Rs.Close Set Rs = Nothing Conn.Close Set Conn = Nothing End Sub above are all the contents of the article" how to use DOM to parse VB.NET XML files ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.