Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
10 KiB

  1. VERSION 5.00
  2. Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "shdocvw.dll"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  5. Begin VB.Form Form1
  6. BorderStyle = 1 'Fixed Single
  7. Caption = "XPathTester"
  8. ClientHeight = 9900
  9. ClientLeft = 2055
  10. ClientTop = 1305
  11. ClientWidth = 14415
  12. LinkTopic = "Form1"
  13. MaxButton = 0 'False
  14. MinButton = 0 'False
  15. ScaleHeight = 9900
  16. ScaleWidth = 14415
  17. Begin SHDocVwCtl.WebBrowser WebBrowser1
  18. Height = 8415
  19. Left = 5400
  20. TabIndex = 11
  21. Top = 1200
  22. Width = 8775
  23. ExtentX = 15478
  24. ExtentY = 14843
  25. ViewMode = 0
  26. Offline = 0
  27. Silent = 0
  28. RegisterAsBrowser= 0
  29. RegisterAsDropTarget= 1
  30. AutoArrange = 0 'False
  31. NoClientEdge = 0 'False
  32. AlignLeft = 0 'False
  33. NoWebView = 0 'False
  34. HideFileNames = 0 'False
  35. SingleClick = 0 'False
  36. SingleSelection = 0 'False
  37. NoFolders = 0 'False
  38. Transparent = 0 'False
  39. ViewID = "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
  40. Location = "http:///"
  41. End
  42. Begin MSComctlLib.TreeView TreeView
  43. Height = 9255
  44. Left = 120
  45. TabIndex = 6
  46. Top = 480
  47. Width = 3495
  48. _ExtentX = 6165
  49. _ExtentY = 16325
  50. _Version = 393217
  51. HideSelection = 0 'False
  52. Indentation = 353
  53. Style = 7
  54. Appearance = 1
  55. End
  56. Begin VB.Frame Frame1
  57. Caption = "Query tester"
  58. Height = 9255
  59. Left = 3720
  60. TabIndex = 3
  61. Top = 480
  62. Width = 10575
  63. Begin VB.ComboBox Combo1
  64. Height = 315
  65. Left = 120
  66. TabIndex = 12
  67. Top = 240
  68. Width = 8895
  69. End
  70. Begin VB.Frame Frame2
  71. Caption = "Syntax used"
  72. Height = 855
  73. Left = 120
  74. TabIndex = 8
  75. Top = 8280
  76. Width = 1455
  77. Begin VB.OptionButton optIE5
  78. Caption = "IE5 syntax"
  79. Height = 195
  80. Left = 120
  81. TabIndex = 10
  82. Top = 600
  83. Width = 1215
  84. End
  85. Begin VB.OptionButton optXPath
  86. Caption = "XPath"
  87. Height = 255
  88. Left = 120
  89. TabIndex = 9
  90. Top = 240
  91. Value = -1 'True
  92. Width = 1215
  93. End
  94. End
  95. Begin VB.CommandButton Command3
  96. Caption = "Query!"
  97. Default = -1 'True
  98. Enabled = 0 'False
  99. Height = 375
  100. Left = 9120
  101. TabIndex = 5
  102. Top = 240
  103. Width = 1335
  104. End
  105. Begin VB.ListBox List1
  106. Height = 6885
  107. ItemData = "Form1.frx":0000
  108. Left = 120
  109. List = "Form1.frx":0002
  110. TabIndex = 4
  111. Top = 720
  112. Width = 1455
  113. End
  114. Begin VB.Label NumberLabel
  115. Height = 255
  116. Left = 120
  117. TabIndex = 13
  118. Top = 7680
  119. Width = 1455
  120. End
  121. Begin VB.Label TimeLabel
  122. BackStyle = 0 'Transparent
  123. Height = 255
  124. Left = 120
  125. TabIndex = 7
  126. Top = 7920
  127. Width = 1455
  128. End
  129. End
  130. Begin VB.CommandButton Command2
  131. Caption = "Open"
  132. Height = 325
  133. Left = 13560
  134. TabIndex = 2
  135. Top = 120
  136. Width = 735
  137. End
  138. Begin VB.CommandButton Command1
  139. Caption = "..."
  140. Height = 325
  141. Left = 13080
  142. TabIndex = 1
  143. Top = 120
  144. Width = 375
  145. End
  146. Begin VB.TextBox Text1
  147. Height = 315
  148. Left = 120
  149. TabIndex = 0
  150. Top = 120
  151. Width = 12855
  152. End
  153. Begin MSComDlg.CommonDialog CommonDialog1
  154. Left = 480
  155. Top = 3720
  156. _ExtentX = 847
  157. _ExtentY = 847
  158. _Version = 393216
  159. End
  160. End
  161. Attribute VB_Name = "Form1"
  162. Attribute VB_GlobalNameSpace = False
  163. Attribute VB_Creatable = False
  164. Attribute VB_PredeclaredId = True
  165. Attribute VB_Exposed = False
  166. Dim oDoc As MSXML2.DOMDocument
  167. Dim oList As MSXML2.IXMLDOMNodeList
  168. Private p_strTempFile As String
  169. Private Sub Form_Load()
  170. p_strTempFile = Environ$("TEMP") & "\XPathTester.xml"
  171. p_DisplayInWebBrowser "<EMPTY/>"
  172. End Sub
  173. Private Sub Command1_Click()
  174. CommonDialog1.ShowOpen
  175. Text1.Text = CommonDialog1.FileName
  176. End Sub
  177. Private Sub Command2_Click()
  178. Dim oNode As Node
  179. Set oDoc = New MSXML2.DOMDocument
  180. oDoc.async = True
  181. oDoc.Load "file:///" & CommonDialog1.FileName
  182. If Not oDoc.parseError.errorCode = 0 Then
  183. MsgBox "Error loading XML: " & vbCrLf & _
  184. oDoc.parseError.reason & vbCrLf & _
  185. "In: " & oDoc.parseError.srcText
  186. Else
  187. Frame1.Enabled = True
  188. Combo1.Enabled = True
  189. Command3.Enabled = True
  190. TreeView.Nodes.Clear
  191. Set oNode = TreeView.Nodes.Add
  192. oNode.Text = "/ (ROOT)"
  193. Set oNode.Tag = oDoc
  194. oNode.Expanded = True
  195. oNode.Selected = True
  196. AddNode oDoc.documentElement, oNode
  197. End If
  198. End Sub
  199. Private Sub Command3_Click()
  200. Dim i As Integer
  201. Dim contextNode As IXMLDOMNode
  202. Dim liStart As LARGE_INTEGER
  203. Dim liEnd As LARGE_INTEGER
  204. On Error Resume Next
  205. Call QueryPerformanceCounter(liStart)
  206. Set contextNode = TreeView.SelectedItem.Tag
  207. ' Set the correct querying syntax
  208. If optIE5.Value = True Then
  209. oDoc.setProperty "SelectionLanguage", "XSLPattern"
  210. Else
  211. oDoc.setProperty "SelectionLanguage", "XPath"
  212. End If
  213. Set oList = contextNode.selectNodes(Combo1.Text)
  214. p_AddStringIfRequired Combo1.Text
  215. List1.Clear
  216. p_DisplayInWebBrowser "<EMPTY/>"
  217. DoEvents
  218. Call QueryPerformanceCounter(liEnd)
  219. TimeLabel.Caption = "Time: " & Format(getSecondsDifference(liStart, liEnd), "##0.000000")
  220. If Err.Number = 0 Then
  221. NumberLabel.Caption = "Total: " & oList.length
  222. DoEvents
  223. If oList.length = 0 Then List1.AddItem "No matching elements"
  224. If (oList.length > 10000) Then
  225. List1.AddItem oList.length & " matching elements"
  226. Else
  227. For i = 1 To oList.length
  228. List1.AddItem CStr(i)
  229. Next
  230. End If
  231. Else
  232. List1.AddItem "Error in query"
  233. NumberLabel.Caption = "Total: 0"
  234. End If
  235. On Error GoTo 0
  236. End Sub
  237. Private Sub List1_Click()
  238. If List1.ListIndex < oList.length Then
  239. p_DisplayInWebBrowser oList.Item(List1.ListIndex).xml
  240. End If
  241. End Sub
  242. Private Sub p_DisplayInWebBrowser(ByVal i_str As String)
  243. FileWrite p_strTempFile, i_str, , True
  244. WebBrowser1.Navigate p_strTempFile
  245. End Sub
  246. Private Function p_Wrap(ByVal i_str As String) As String
  247. Dim intLength As Long
  248. Dim intCurrentPosition As Long
  249. Const intMax As Long = 80
  250. Dim str As String
  251. str = i_str
  252. intLength = Len(i_str)
  253. intCurrentPosition = Int(intLength / intMax) * intMax
  254. Do While (intCurrentPosition > 0)
  255. str = Mid(str, 1, intCurrentPosition) & vbCrLf & Mid(str, intCurrentPosition)
  256. intCurrentPosition = intCurrentPosition - intMax
  257. Loop
  258. p_Wrap = str
  259. End Function
  260. Private Sub AddNode(ByRef oElem As IXMLDOMNode, Optional ByRef oTreeNode As Node)
  261. Dim oNewNode As Node
  262. Dim oNodeList As IXMLDOMNodeList
  263. Dim i As Long
  264. Dim bRoot As Boolean
  265. Set oNewNode = TreeView.Nodes.Add(oTreeNode, tvwChild)
  266. oNewNode.Expanded = False
  267. If TypeOf oTreeNode.Tag Is DOMDocument Then
  268. ' This is the root node
  269. oNewNode.Expanded = True
  270. bRoot = True
  271. End If
  272. oNewNode.Text = oElem.nodeName
  273. Set oNewNode.Tag = oElem
  274. If bRoot Then
  275. AddNodeList oElem.childNodes, oNewNode
  276. Else
  277. Set oNewNode = TreeView.Nodes.Add(oNewNode, tvwChild)
  278. oNewNode.Expanded = False
  279. oNewNode.Text = "parsing"
  280. Set oNewNode.Tag = Nothing
  281. End If
  282. End Sub
  283. Private Sub AddNodeList(ByRef oElems As IXMLDOMNodeList, ByRef oTreeNode As Node)
  284. Dim i As Long
  285. For i = 0 To oElems.length - 1
  286. AddNode oElems.Item(i), oTreeNode
  287. Next
  288. End Sub
  289. Private Sub TreeView_Expand(ByVal Node As MSComctlLib.Node)
  290. If Node.children = 1 Then
  291. ' Check if the single child is indeed the dummy child
  292. If Node.Child.Tag Is Nothing Then
  293. ' Remove the dummy
  294. TreeView.Nodes.Remove (Node.Child.Index)
  295. ' Add the child nodes to the treeview
  296. AddNodeList Node.Tag.childNodes, Node
  297. End If
  298. End If
  299. End Sub
  300. Private Sub p_AddStringIfRequired(i_str As String)
  301. Dim intIndex As Long
  302. Dim str As String
  303. str = LCase$(i_str)
  304. For intIndex = 0 To Combo1.ListCount - 1
  305. If (str = LCase$(Combo1.List(intIndex))) Then
  306. Exit Sub
  307. End If
  308. Next
  309. Combo1.AddItem i_str, 0
  310. End Sub
  311. Private Sub TreeView_NodeClick(ByVal Node As MSComctlLib.Node)
  312. Combo1.Text = Replace$(Mid$(Node.FullPath, 9), "\", "/")
  313. p_AddStringIfRequired Combo1.Text
  314. End Sub