Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use DOM to parse VB.NET XML files

Shulou Source: shulou.com Published: 2022-06-02 08:52:29 09月25日 Update

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!

Tags: Files nodes articles generation content characters attributes proficiency security not so much code multiple most strings children actual actually objects data methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno NVidia Shulou Technology Shulou Tech Info