Trong mẫu mã, tập tin nguồn có cấu trúc được thể hiện trong hình 11-1. Nút gốc là thế và có một số các nút con được đặt tên QuoteTable. Mỗi nút QuoteTable chứa một phần tử nguồn có chứa các văn bản của một trích dẫn nội dung bài viết này. Một phần kết quả của phương pháp tìm kiếm trong Ví dụ 11-4 được hiển thị trong Ví dụ 11-5. Thông báo danh sách cho thấy các nút duy nhất với tên của Source. | 258 Part II Microsoft Office and XML Listing 11-4 Selecting Specific Nodes in the DOM Dim oDOM As Dim oNL As IXMLDOMNodeList Set oDOM New DOMDocument40 C _ SelectionLanguage XPath Set oNL . selectNodes Source In this code sample the source file has the structure shown earlier in Figure 11-1. The root node is Quotes and there are a number of child nodes named QuoteTable. Each QuoteTable node contains a Source element that contains the text of a quote. A portion of the result of the method search in Listing 11-4 is shown in Listing 11-5. Notice how the list shows only nodes with the name of Source. Listing 11-5 Results of the selectNodes Method Source Joke-Of-The-Day Source Source Pat Newberry Source Source Tammy Vanoss Source Source Joke-Of-The-Day Source Source Tammy Vanoss Source Source Joke-Of-The-Day Source But what would happen if the structure of the XML were not so regular In other words notice how the current structure is very predictably Quotes QuoteTable Source. Each QuoteTable element contains elements for Date Source Quote and QuoteKey. However Figure 11-2 shows a revised structure where one of the QuoteKey elements in just one of the QuoteTable nodes contains an additional Source element. Without changing the code this irregularly placed element can still be found and it will be grouped with the rest of the nodes that follow the more predictable structure. The list of nodes containing Source elements is shown in shortened form in Listing 11-6. Notice how the results do not distinguish where a node came from in the source hierarchy. All that matters is whether the node matched the search pattern. Chapter 11 Working with the MSXML DOM 259 Figure 11-2 Revised XML structure with an oddly placed element Listing 11-6 Results of a selectNodes Search Including an Irregularly Structured Element Source Anyone Source Source This is an element that does not fit the regular structure .