I'm trying to create a function in C# that will try to automatically generate a closing XML tag when the user types </
.
Let's say I have following string:
<books>
<book>
<author>Tolkien</author>
<title>Fellowship of the Ring</title>
</book>
<book>
When the user types </
, this should be directly appended with the string book>
.
I am kind of lost on how to find the last unclosed tag (in this case <book>
programmatically. Is a regex the best way to do this? Using an XML parser seems to be out of the question since the XML at this point is not valid.