Class XMLReferenceCollector

java.lang.Object
org.eclipse.lemminx.extensions.index.XMLReferenceCollector

public class XMLReferenceCollector extends Object
Collects grammar references and symbol names from XML content using LemMinX's own XMLScanner. No DOM is built — only the relevant token values are extracted via a lightweight token scan.

Uses the XMLScanner which is fault-tolerant (handles malformed XML) and lighter than SAX (no factory, no JDK XML parser stack).

All comparisons on token text are done char-by-char on the source CharSequence — no intermediate String allocations for checks. Strings are only created for values that are actually collected into the result set.

Collects:

  • <?xml-model href="..."?> — grammar file path
  • xsi:schemaLocation — grammar file paths (namespace-URI pairs)
  • xsi:noNamespaceSchemaLocation — grammar file path
  • xs:include/xs:import schemaLocation — grammar file path
  • <!DOCTYPE ... SYSTEM "..."> — DTD file path
  • href and location attributes (XInclude, XSLT import/include, XLink, WSDL import)
  • Element names (for symbol-level cross-file references)
  • type, ref, base, name, substitutionGroup attribute values (for XSD cross-file)
  • Constructor Details

    • XMLReferenceCollector

      public XMLReferenceCollector()
  • Method Details

    • collect

      public static Set<String> collect(CharSequence text)
      Extracts all reference tokens from XML content and returns them as a name set.

      Use case: When indexing order.xml whose content is:

         <?xml-model href="schemas/order.xsd"?>
         <root xsi:noNamespaceSchemaLocation="common.xsd"/>
       
      returns {"schemas/order.xsd", "order.xsd", "common.xsd", "root", …}. This set is fed to BloomFilter.create(java.util.Collection<? extends java.lang.CharSequence>) so that later queries like mightContain("order.xsd") return true in O(1) time.
      Parameters:
      text - raw XML content, possibly truncated to the first 64 KB for large files.
      Returns:
      the set of collected names (file paths, element names, attribute values).
    • collect

      public static Set<String> collect(CharSequence text, List<IGrammarReferenceContributor> contributors)