I'm using ScintillaNet to create an editor for MSBuild files. One of the features of that editor would be autocomplete.
My idea was to parse the XSD schema of MSBuild to obtain the allowed elements and attributes. That problem is solved.
My current problem is that I have to know "where" in the schema the user is in order to show context-sensitive information. I basically need to parse an XML document. Sounds easy, right? Wrong: the document is currently being edited, so it's probably not valid XML.
So, I'm looking for a way to construct a path of element names from the root of the document to the current position (the text cursor). I think we can assume that everything is valid until the last element.开发者_高级运维 I don't really want code, just a some steps to get me started.
Thanks.
Personally I would parse the text up to the user's cursor keeping a stack of the elements that are encountered - pushing them on as they are opened, and popping them of when closed. You'll be able to use the state of the stack to give you the element that the user is currently in.
You'll need to take into account that the user may be editing a node name - the state your parser is in at the end of the process will be able to give you a good indication as to what the user is currently editing.
edit: I know you didn't as for code, but I might be able to throw something together quickly if you need it.
精彩评论