XML file reading

xiaoxiao2021-03-06  37

When I do a project, there is a need for a dynamic unlimited linkage. Since I am lazy to find the relevant code, I have not met the demand, one of which has an article with JavaScript to implement an infinite-level linkage menu with JavaScript, and we can combine ASP to complete the reading of database values. And write to the XML file, read out with JavaScript and control it. The key here is to read the N layer data classes in the database: My database table structure is like this: 'TBL_CLASS column name data Type length Description ClassID INT 4 Class IDModuleId INT 4 Module IDGroupID INT 2 Identify a Group ClassName NVARCHAR 50 Category Name ParentID INT 2 Connect to Group (0 is a parent class) '############################################## # My ASP code is as follows ######################### Ignore the code of the connection database. 'Function Name: OpenXML (filename)' Entry parameters: filename needs to be connected or opened XML file name 'return value: XMLDOC is an object that successfully loads an XML document.

'There are errors, print error message strerror' ----------------------------------------- ------- function OpenXml (filename) dim strSourceFile, XmlDoc, strErrorstrSourceFile = filenameSet XmlDoc = Server.CreateObject ( "Microsoft.XMLDOM") 'Create instance XMLDOM XmlDoc.async = false xmlDoc.load (strSourceFile) OpenXml = XmlDoc .parseerror.errorcode if XmlDoc.parseerror.errorcode <> 0 then strError = "

error" & XmlDoc.parseerror.errorcode "" strError = strError & XmlDoc.parseerror.reason & "
" strError & = strError & XmlDoc.parseerror .url & "
" strError = strError & XmlDoc.parseerror.line & "
" strError = strError & XmlDoc.parseerror.filepos & "
" strError = strError & XmlDoc.parseerror.srcText & "
" response.write strError 'output error Else Set OpenXML = XMLDoc 'Returns End If End Function' ------------------------------------- ----------- 'function name: closexml ()' parameter: xmldoc XML Components College ------------------------ ------------------------ Function Closexml (Xmldoc) if isobject (xmldoc) THEN SET XMLDOC = Nothing end if End function '------ --------------------------------- --------- 'function name: selectxmlnode' parameter: xmldoc XML component instance 'E element name' return Element instance '----------------- ----------------------------- Function SelectxmlNode (Xmldoc, e) Dim n set n = xmldoc.selectsinglenode ("//" & e) set selectXmlNode = n end function Dim n, np, MaxGroup, root, xmlDoc, nt, filename, s, ss, TorFfilename = server.mappath ( "demo.xml") set xmlDoc = openXML (filename) 'opens XMLRemoveAllNodes xmlDoc , "Root" 'Clear root and the subproces below it,

This makes it possible to read and write SET ROOT = XMLDoc.createElement ("root") xmldoc.appendchild root 'Create a top element SQL = "SELECT MAXID" from TBL_CLASS "' Read the maximum level SET RS = cn.execute (SQL) if ISNULL (RS (0)) THEN MAXGROUP = 0 else maxgroup = rs (0) If null indicates no data S = "": ss = "" set nt = xmldoc.createElement ("item") NT .settribute "text", "Please select" root.appendchild NT 'Create an element for i = 1 to maxGroup' Start loop SQL = "SELECT * from tbl_class where groupid =" & i 'by the underlying to the top layer Read SET RS = Cn.execute (SQL) Torf = false 'creates a "Please select" for each layer.

Do WHILE RS.EOF = FALSE 'Start reading the underlying data set n = xmldoc.createElement ("Item" & r ("ClassID") "Create a tag element N.SetAttribute" text "named Item ID number RS ("classname") set its attribute "text" to the classname n.settribute "value" in the database table, RS ("ClassID") 'Sets its attribute "value" to the ClassID in the database table. IF RS ("ParentID")> 0 THEN 'is SET NP = SELECTXMLNODE (XMLDoc, "Item" & RS ("ParentID")) "ParentID")' False Ten 'If the Torf is a false value set nt = xmldoc.createElement ("iTEM") Create an element saved in NT NT.settribute "text", "Please select" Set its text property to "Please select" np.appendchild NT 'NP adds it as a child element end if Torf = true' Set true np.appendchild n 'NP PCPpend NPPpend NPpend NPpend NPPpendChild N' If it is the first layer of data, add it to root One child element end if rs.movenext 'Next pointer loop ss = ss & " S = S & ", 'SELECT" & I & "'" 'puts each to the document S = MID (S, 2) // call xmlselect.js