Solved

How do I validate XML against schema during serialization

Posted on 2010-09-10
5
741 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 50 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON  parse help 7 40
how to double quote a string for an inline sql statement. 8 73
Customizing XML with Powershell 2 23
Groupbox Control ? 2 18
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 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