Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I validate XML against schema during serialization

Posted on 2010-09-10
5
Medium Priority
?
768 Views
Last Modified: 2012-05-10
i know how to validate an xml file against a schema during deserialization. i have been searching the internet for an example of serialization validation and have found none. is this possible in c#? any help will be greatly appreciated.


0
Comment
Question by:codechewer
5 Comments
 
LVL 3

Expert Comment

by:vusov
ID: 33652372
I think xml schema validation occurs during serialization.
0
 
LVL 8

Accepted Solution

by:
redpipe earned 200 total points
ID: 33680050
I don't quite understand what you intend to do..?

If you already have an instantiated object and provide the correct classdef in the typeof parameter of the XmlSerializer method, then the conversion to a XMLified string should go without problems. (http://www.dotnetjohn.com/articles.aspx?articleid=173)

Of course, if you use a generic serialization method (as shown here http://www.dotnetjohn.com/articles.aspx?articleid=173) or if there is a mismatch between the ClassDef and XSD exceptions might/will occur.

Then a "generic" validation method of a XMLstring and corresponding XSDstring can be found at http://stackoverflow.com/questions/2780327/validate-xml-with-a-xsd-schema-without-changing-the-xml-using-c

Hope this helps, if not please provide more information.
0
 

Author Comment

by:codechewer
ID: 33693216
I wanted to validate my xml document while in the  process of serializing the class into the xml document.

Though the classes were created from the schema, there are some conditions that made the serialized xml document not conform to the xsd structure and data-type requirement.

I did not want to finish serializing the class into an xml document and then attempt to re-read it into memory just for the purpose of  validating the document against the schema.

but I found out that you can only validate an xml document by reading the outputed xml document back into memory and there and then only can you validate the document against its schema to discover errors in the document if any.

Unless there is a smarter way of validating the xml string during the process of serializing the class into the xml file,  i will close this question and award the points to redpipe who pointed me to the only method i know for validating an xml document against its schema.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34881974
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question