I talked about using XML file in the last few posts, and especially pointed out the advantage of using xml as interface.
For example: Your mate send you a xml file which contains the information in a format that you defined. You can easily
read and write code without actually getting the xml file because you design the schema.
Now that I successfully create such file, I was wondering the ability to handle errors. I am more aware that what I am gonna
process (xml file) is actually violate the designed format. So I did some research, and did the following things:
Here are some code examples:For example: Your mate send you a xml file which contains the information in a format that you defined. You can easily
read and write code without actually getting the xml file because you design the schema.
Now that I successfully create such file, I was wondering the ability to handle errors. I am more aware that what I am gonna
process (xml file) is actually violate the designed format. So I did some research, and did the following things:
- Generate the schema xsd file for my designed xml file
- Before processing, using schema xsd file to validate against xml file
- Report error
if (Validate(strFile, Properties.Settings.Default.schema) != true)
{
MessageBox.Show("XML file doesn't matches the schema! Please verify the input format!");
return;
}
static int numErrors = 0;
static string msgError = "";
private static void ErrorHandler(object sender, ValidationEventArgs args)
{
msgError = msgError + "\r\n" + args.Message;
numErrors++;
}
private static bool Validate(string xmlFilename, string xsdFilename)
{
return Validate(GetFileStream(xmlFilename), GetFileStream(xsdFilename));
}
private static void ClearErrorMessage()
{
msgError = "";
numErrors = 0;
}
// returns a stream of the contents of the given filename
private static Stream GetFileStream(string filename)
{
try
{
return new FileStream(filename, FileMode.Open, FileAccess.Read);
}
catch
{
return null;
}
}
private static bool Validate(Stream xml, Stream xsd)
{
ClearErrorMessage();
try
{
XmlTextReader tr = new XmlTextReader(xsd);
XmlSchemaSet schema = new XmlSchemaSet();
schema.Add(null, tr);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(schema);
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(ErrorHandler);
XmlReader reader = XmlReader.Create(xml, settings);
// Validate XML data
while (reader.Read())
;
reader.Close();
// exception if validation failed
if (numErrors > 0)
throw new Exception(msgError);
tr.Close();
return true;
}
catch
{
msgError = "Validation failed\r\n" + msgError;
return false;
}
}
505 comments:
«Oldest ‹Older 401 – 505 of 505Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
Best python certification in kanchipuram
This Blog is very Nice and very useful to us...
CEH Training Institute in Chennai
| CEH Course in velachery
| CEH Training Institute in Keelkattalai
| CEH Course in Perungudi
This is excellent information. It is amazing and wonderful to visit your site.Thanks for
sharing this information, this is useful to me…
Best PYTHONE certification in
kanchipuram
This is excellent information. It is amazing and wonderful to visit your site.Thanks for
sharing this information, this is useful to me…
Best PYTHONE certification in
kanchipuram
Thanks for giving nice information from your blog...It's really an amazing post... Best Advanced MATLAB Course in Kanchipuram|
Very Informative...Glad to find your blog...Keep Sharing...
CCNA Training in Chennai | CCNA Training in Chromepet
This is excellent information. It is amazing and wonderful to visit your site.Thanks for
sharing this information, this is useful to me…
Best Advanced .Net training
Institute in chennai
Very Informative...Glad to find your blog...Keep Sharing...
Java Script Course in Chennai | Java Script Course in Medavakkam
Nice Post! It is really interesting to read from the beginning and Keep up the good work and continue sharing like this.
Best RPA training Institute in kanchipuram
Very Informative...Glad to find your blog...Keep Sharing...
Ethical Hacking Training in Chennai | Ethical Hacking Training in St.Thomas Mount.
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.…
Selenium Training Course in Chennai |
Selenium training Course in OMR
Very Informative...Glad to find your blog...Keep Sharing...
Best Animation Course in Chennai | Best Animation Course in OMR
This is excellent information. It is amazing and wonderful to visit your site.Thanks for
sharing this information, this is useful to me.
Best Web Design training Institute in
kanchipuram
Nice blog…. with lovely information. Really very useful article for us thanks for sharing such a wonderful blog. Keep updating…..
Best Linux training Institute in kanchipuram
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me.
Best Linux training Institute in kanchipuram
This blog is really useful and it is very interesting thanks for sharing, it is really good and exclusive.
Electrical Project Center in Chennai | Electrical Project Center in Chrompet
Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
Bootstrap Training in Chennai |
Bootstrap training in Chromepet
This Blog is very Nice and very useful to us...
Best Oracle Training Institute in Chennai
| Oracle Training in velachery
| Best Oracle Training Institute in Chromepet
| Oracle Training in Perungudi
Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
Advanced SoftwareTesting Course Training Institute in Chennai | Advanced SoftwareTesting Course in Chrompet
Thank u for sharing such nice information.!! Total recall is also good one.!! PMP Ceritification in Chennai|
very useful really good information thanks for posting such a good information it will hepls the people a lot keep it up.. CCNA Exam Center in Chennai|
"nice blog and very interesting. . .
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
very useful really good information thanks for posting such a good information it will hepls the people a lot keep it up.. Best MATLAB Training Center In Chennai|
very useful really good information thanks for posting such a good information it will hepls the people a lot keep it up , Regards, Best PMP Certification In Chennai|
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.and once again thanks for sharing.….. Best ISTQB Certification In Chennai|
I thank you for the information and articles you provided
its very interesting post, good job. Best ISTQB BCS Certification In Chennai|
very nice post what a fantastic information you sharing. Keep sharing your post regularly.. Best CISM Certification in Chennai |
This post was quite awesome and interesting to read. Congrats for your work. Thanks a lot for providing this with us. Keep on updating this with us regularly: Best CISA Certification in Chennai |
This post was quite awesome and interesting to read. Congrats for your work. Thanks a lot for providing this with us. Keep on updating this with us regularly: Best CISA Certification in Chennai |
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge. Best CCNA Training Center in Chennai |
Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. Best AWS Training Center in Chennai |
Hi, am a big follower of your blog. The best thing is that your blog really informative thanks for your great information Best Microsoft Azure Training Center in Chennai |
Wonderful post. Thank you for updating such a good post.. Best Linux administration Training Center in Chennai |
Your blog was so informative, Really I thanks a lot for sharing such a awesome blog., Best RHCSA Training Institute In Chennai |
You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the particular topic. Best RHCE Training Institute In Chennai |
You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the particular topic. Best RHCE Training Institute In Chennai |
Really an amazing post..! By reading your blog post i gained more information. Best Microsoft Advanced Excel Training Center in chennai |
I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! Best CEH Training institute in chennai |
Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing.. Best Software Testing Training Center in chennai
|
this blog is really useful and it is very interesting thanks for sharing , it is really good and exclusive. Best Prince 2 Exam center in chennai|
Good one, it is very useful for me to learn and understand, thanks for sharing your information and ideas.. keep rocks.. Best Agile Scrum Master Exam center in chennai|
Good one, it is very useful for me to learn and understand, thanks for sharing your information and ideas.. keep rocks.. Best Agile Scrum Master Exam center in chennai|
very nice post what a fantastic information you sharing. Keep sharing your post regularly.. Best Embedded System Exam center in chennai|
Great and useful post.Thanks for taking time to share this post. Best Machine Learning Training in chennai|
Great tips and its so easy to understand. really You explain everything in detailed manner and it was very interesting to read. Thank you. Best Data Science Training in chennai|
Nice blog, here I had an opportunity to learn something new in my field. I have an expectation about your future post so please keep updates.. Best PCB design Training center in chennai|
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work. Best Matlab Training Center in Chennai |
Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.… Best Oracle Certifications in Chennai |
Thanks for another great post. The place else may anyone get that type of information in such a perfect way of writing? I’ve a presentation next week, and I’m at the look for such information. Best CCNA Training Institute in Chennai
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information and it is very useful to me... RHCSA Training Center in Chennai|
Great the given information and after refer that post,i get new energy because of all given information very excellent and real words to implemented for you.Thank you so much shared that valuable information. PCB Design Training Center in Chennai ! velachery|
These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice. JAVA Training Center in Chennai |
Thank you so much for sharing such an amazing post with useful information with us. Keep updating such a wonderful blog…. Photoshop Training institute in Chennai |
Nice blog, here I had an opportunity to learn something new in my field. I have an expectation about your future post so please keep updates. illustrator Training institute in Chennai |
Very nice blogs!!! I have to learning for lot of information for this sites...Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.… ISTQB Certification in Chennai |
This is such a good post. One of the best posts that I\'ve read in my whole life. I am so happy that you chose this day to give me this..please share more information!!
Android Training in Chennai
Android Online Training in Chennai
Android Training in Bangalore
Android Training in Hyderabad
Android Training in Coimbatore
Android Training
Android Online Training
Very happy to see this blog. Gives a wonderful information with coded explanaion. Thank you for this blog. very useful to me. Prince2 Certification Center in Chennai |
Thanks for your informative Information.Your post helped me to understand the future and career prospects. Keep on updating your blog with such awesome article. Agile Scrum Master Certification Center in Chennai |
Thanks for sharing this informative blog. I have read your blog and I gathered some valuable information from this blog. Keep posting. BBA Project center in chennai and velachery |
Thanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well.
Data Science Training Institute in Bangalore
Awesome post. Really you have shared a very informative concept... Thank you for sharing. Keep on updating... EEE Project center in chennai and velachery |
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas. UFT Training center in chennai |
It is really a great and useful piece of information. I am glad that you shared this helpful info with us. Please keep us up to date like this. Thank you for sharing. Azure Training institute in Chennai and Velachery |
Excellent blog with useful concept. Really I feel very happy to see this informative blog, Thanks for sharing such a nice blog.. Tally Training Institute in Chennai|
Very nice post here and thanks for it .I always like and such a super blog of these post.Excellent and very cool idea and great blog of different kinds of the valuable information's. Python Training Institute in Chennai |
awesome way to get exert tips from everyone,not only i like that post all peoples like that post,because of all given information was wonderful and it's very helpful for me. CCNA Exam Center in Chennai |
In the beginning, I would like to thank you much about this great post.I like your writing style and I hope you will keep doing this good working AWS Exam Center in Chennai |
Wow...Excellent informative blog, really helpful. Thank you. Final Year Projects For Phd in Chennai |
It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. Final year projects For Engineering Students in Chennai |
Thank you for sharing the information here. Its much informative and really i got some valid information. You had posted the amazing article. Final year projects For CSE Students in Chennai |
I am joyful to read this post, its an attractive one. Thanks for this amazing post.. Final year projects For IT in Chennai |
I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.. Final year projects For EEE in Chennai |
this blog is really useful and it is very interesting thanks for sharing , it is really good and exclusive. PMP Certification Center in Chennai |
Nice Blog very useful and attractive information. Thank You.
Cyber Security Course in Bangalore
This is excellent information. It is amazing and wonderful to visit your site.Thanks for
sharing this information, this is useful to me. Photoshop Training institute in Chennai |
Great post. Thank you for the information and waiting for your new post.
Cyber Security Training in Bangalore
Awesome blog great information thank you.
360DigiTMG Data Science Course in Hyderabad
Great Blog very informative and really i got some helpful information thank you.
360DigiTMG Data Science Training in Hyderabad
Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!PCB Design Training in Chennai |
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Hardware and Networking Training institute in Chennai |
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information and it is very useful to me... Microsoft Azure Certification Center in Chennai |
Really very great information to be provided and the All points discussed were worth reading and i’ll surely work with them all one by one. Photoshop Training Institute In Chennai |
Information in the blog was very informative and useful thank you.
Data Analytics Certification Training 360DigiTMG
Your blog was so informative, Really I thanks a lot for sharing such a awesome blog. Tally Erp9 Training Center in Chennai |
Nice Post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog as updated. JAVA Training Institute In Chennai |
Nice Post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog as updated. JAVA Training Institute In Chennai |
very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing. Final year projects For EEE in Chennai |
Impressive blog with lovely information. really very useful article for us thanks for sharing such a wonderful blog... Final year projects For BCA in Chennai |
Your blog is awesome..You have clearly explained about it ...Its very useful for me to know about new things..Keep on blogging.. Final year projects For CSE in Chennai |
I learned so many things from your blog, keep sharing.. PMP Certification Center in Chennai|
One of the top quality blog with excellent information thanks for sharing.
Ethical Hacking Course in Bangalore 360DigiTMG
It's really good to read this blog. Keep updating.
multithreading example in java
while do loop java
string operations in java
non primitive data types in java
what is oops concept
angularjs interview questions for freshers
I got more useful information from this thanks for sharing this blog.
why seo is important for your business
how to learn pronunciation of english words
advantages and disadvantages of html
selenium automation
salesforce interview questions and answers
salesforce testing interview questions
blue prism interview questions and answers
Very Nice article, thanks for sharing the article.
devops methodology
habits of success
mobile application testing tools
why web development is important
advanced excel interview questions
ethical hacking books
Really Nice Information It's Very Helpful All courses Checkout Here.
data science course noida
thank you for the information provided, we are waiting for the next info
informative article.thank you.Angular training in Chennai
Nice article. I liked very much. All the information given by you are really helpful for my research. keep on posting your views.
data scientist course aurangabad
Die Technologie entwickelt sich schneller denn je und schneller als Sie denken. Diese aufkommende Technologie wird unsere Lebensweise verändern.
Informative blog. Thank you for sharing.
Cloud-Computing Courses in Chennai
php course in chenna
Software training institute in chennai
best devops training in chennai
blue prism course in chennai
best rpa training in chennai
azure certification in chennai
rpa uipath training in chennai
Really Nice Information It's Very Helpful All courses Checkout Here.
data scientist courses in aurangabad
Needed to compose a very few words to thank you yet again
regarding the nice suggestions, you’ve contributed here.
Aimore Technologies offers Data Analytics Courses In Chennai with 10+ years of experience. We are offering online and classroom training. Visit Us: Data Analytics Courses In Chennai
Smart blog
Post a Comment