Search code examples
xmlblazormonaco-editor

when I load an XML document to the Monaco editor, how can I get XML information on a mouse click or select?


I need to perform various XML structure related operations on an XML document. I can load it into the Monaco editor and get nice syntax highlighting and various other services. But can I get the node and tag information from a mouse click or select or KeyUp event or will I need to have an XDocument object and use the line number and column information from the editor events to synchronize?

I am building a Blazor client side application, with the BlazorMonaco project and setting the language to 'xml'. Any other ideas?


Solution

  • The monaco editor only comes with simple support for most languages, which is mostly syntax highlighting (and no parsing). That means it cannot give you can syntactical information about the document content.

    Intstead you need to implement your own parser for XML (e.g. using ANTLR4 and the XML grammar).