Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find position of XmlSchemaException in the XMLDocument

Status
Not open for further replies.

adam0101

Programmer
Jun 25, 2002
1,952
US
I'm creating an application that allows a user to validate an XML document and update the document where the errors occur. First I load the XML document into a TreeView. Then I validate then document against a schema, which gives me a bunch of XmlSchemaException objects.

The problem is this - how do I find the error in the TreeView based on the schema exception? The exception tells me what line number the error occurs, but how do I translate that into an element in the XmlDocument, or even better - a node of the TreeView?

I found this article on MSDN that shows how to extend the XMLDocument object to capture line numbers by extending the XMLElement object. But when I populate the TreeView, I do so by doing a:

[tt][blue]For Each[/blue] node [blue]As[/blue] XmlNode [blue]In[/blue] document.ChildNodes[/tt]

I can't cast an XmlNode into my custom XmlElement, and there isn't a ChildElements collection as far as I can tell, so I'm kinda stuck.

Any ideas?

Thanks,

Adam
 
glad we could help

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
FYI, I looked at how they did it and this was the line I was missing:
Code:
[blue]Dim[/blue] lineInfo [blue]As[/blue] IXmlLineInfo = [blue]CType[/blue](node, IXmlLineInfo)
I was trying to convert the node directly into the extended object instead of its interface.

Adam
 
I thought you desevered a star for that Chrissie...

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
yep me too.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Let me know how that works out for ya. :p

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top