Solved

How do I validate XML against schema during serialization

Posted on 2010-09-10
5
746 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

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, …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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