I want to implement intellisense in an xml editor using XmlSchemaValidator. The user types "<" and I want to suggest the allowed elements based on an XSD file. For this I need to validate the typed XML content which is of course not complete. Sample:
<element1 atb="1">
<element2>
< ==> suggest element3
So the validator needs to validate element1,atb and element2. Then I can use validator.GetExpectedParticles. Since I don't want to parse the content for myself I want to use XmlReader. But the XmlReader isn't able to tell me when he is at EOF (just providing him with the xml-string without the last "<" in the sample).
string s = "<element1 atb='1'><element2>";
StringReader sr = new StringReader(s);
XmlReader xr = XmlReader.Create(sr);
while (!xr.EOF)
{
xr.Read();
// ... validate element, attributes ... //
}
My problem is, that the xr.EOF() never returns true so I can't know when to stop reading and validating. Any Ideas?
Thank you
<element2>with</element1>in your string, you will see thatxr.EOFwill become true when you reach the end. That because XmlReader is supposed to work with complete and well-formed Xml's. - digEmAll