Solved

How do I validate XML against schema during serialization

Posted on 2010-09-10
5
740 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 142

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cant save 3D 4 20
updating order of the rows, N+1 query issue, C#, asp.net, MVC, SQL Server 3 26
ebay devID, appID, certID, userToken 2 27
start a process from a service 3 22
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 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