Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My C#/.NET application reads XML files that are manually edited by the users. The allowed elements and tags are described in the application's documentation. I'm using LINQ to extract data from the XML file.

Before extracting data from the XML file, I'd like to validate it to see if it has the expected structure. If not, it would be nice to have information about what is wrong so that I can give some feeback to the user.

What's the simplest way to do this in C#?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can validate xml files against XSD.

Hope this will help...

EDIT

This article explains all possible ways to validate xml, using C#
How To Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET

IMO best option is to use XSD.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...