1 // =================================
 2 // Copyright (c) 2024 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 using System.Collections;
 8 
 9 namespace System.Xml
10 {
11     public class BuildIndexVisitor : Visitor
12     {
13         public BuildIndexVisitor(Map<stringElement*>& index_) : index(index_)
14         {
15         }
16         public override void BeginVisit(Element& element)
17         {
18             string id = element.GetAttribute("id");
19             if (!id.IsEmpty())
20             {
21                 index[id] = &element;
22             }
23         }
24         private Map<stringElement*>& index;
25     }
26     
27     public void BuildIndex(Document* document)
28     {
29         BuildIndexVisitor visitor(document->Index());
30         document->Accept(visitor);
31     }
32 }