📄 search-dom.aspx
字号:
<%@Page Language="VB" %>
<%@Import Namespace="System.XML" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Searching an XML document using the DOM</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Searching an XML document using the DOM</span><hr />
<!--------------------------------------------------------------------------->
<div id="outDocURL" runat="server"></div>
<div id="outError" runat="server"> </div>
<div id="outResults" runat="server"></div>
<script language="vb" runat="server">
Sub Page_Load()
'create physical path to booklist.xml sample file (in same folder as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.xml"
'create a new XMLDocument object
Dim objXMLDoc As New XmlDocument()
Try
'load the XML file into the XMLDocument object
objXMLDoc.Load(strXMLPath)
outDocURL.innerHTML = "Loaded file: <b>" & strXMLPath & "</b>"
Catch objError As Exception
'display error details
outError.innerHTML = "<b>* Error while accessing document</b>.<br />" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution
End Try
'now ready to parse the XML document
'it must be well-formed to have loaded without error
'create a string to hold the matching values found
Dim strResults As String = "<b>List of authors</b>:<br />"
'create a NodeList collection of all matching child nodes
Dim colElements As XmlNodeList
colElements = objXMLDoc.GetElementsByTagname("AuthorName")
'iterate through the collection getting the values of the
'child #text nodes for each one
Dim objNode As XmlNode
For Each objNode In colElements
strResults += objNode.FirstChild().Value & "<br />"
Next
'then display the result
outResults.innerHTML = strResults 'display the result
End Sub
</script>
<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -