473,473 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sample code demonstrating how to load an XSD-validated XML file into a C# object

This code assumes that you have a LoggingMessagesDefinition.XSD file, a
LoggingMessagesDefinition.XML file that conforms to the XSD, and that
you have used the XSD.exe utility to create a c# .cs file (containing
the arbitrary object 'ObjectFromXSD') from the XSD.

using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

public void LoadToObject(ObjectFromXSD loggingMessage)
{
string filename = @"C:\LoggingMessagesDefinition";

string MessageDataXmlFile = filename + ".xml";

string MessageDataXsdFile = filename + ".xsd";

XmlSchemaCollection myXmlSchemas = new XmlSchemaCollection();
myXmlSchemas.Add("http://tempuri.org/LoggingMessagesDefinition.xsd",
new XmlTextReader(MessageDataXsdFile));

XmlValidatingReader myXmlValidatingReader = new
XmlValidatingReader(new XmlTextReader(MessageDataXmlFile));

myXmlValidatingReader.Schemas.Add(myXmlSchemas);

myXmlValidatingReader.ValidationType = ValidationType.Schema;

loggingMessage = new ObjectFromXSD();

XmlSerializer loader = new XmlSerializer(typeof(ObjectFromXSD));

loggingMessage =
(ObjectFromXSD)loader.Deserialize(myXmlValidatingR eader);
}

May 31 '06 #1
0 1321

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: tgtt | last post by:
the schema is: http://www.web3d.org/specifications/x3d-3.0.xsd when use SOM to load as: .... SchemaCache = new ActiveXObject("Msxml2.XMLSchemaCache.4.0"); SchemaCache.add("","x3d-3.0.xsd");...
1
by: jrefactors | last post by:
I want to ask if any tools can generate sample XML from XSD? please advise. thanks!!
0
by: dc | last post by:
article and sample code demonstrating interop between Apache XMLBeans 1.0.x and .NET . http://blogs.msdn.com/dotnetinterop/archive/2005/02/11/371035.aspx
5
by: David Coppit | last post by:
Hi all, Most smart pointers remove the need to call delete. What I want is a pointer that turns delete into a no-op for "unauthorized" clients. The reason is that I'm generating code from...
2
by: Pet Matrix. | last post by:
Hi, I am trying to validate an XML file using the XmlValidatingReader and XmlUrlResolver. The code for which goes like this: // Read the XML file. XmlTextReader xmlReader = new XmlTextReader(...
3
by: Steve Franks | last post by:
I have a need to create a customer satisfaction surveys in ASP.NET. Nothing too fancy, just a handful of questions. Can anyone guide me to an ASP.NET sample application which demonstrates how to...
1
by: Nettar | last post by:
Hi, Is it possible to generate a sample DOM tree for a given XSD programatically using Java? I know that some tools can generate a sample XML for the given XSD. I want to do this...
0
by: Jan Jones | last post by:
Hi, I have two XSDs both in seperate namespaces, Child is an extension of the abstract Base: <?xml version="1.0" encoding="utf-8"?> <xs:schema id="Base"...
3
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I need to build an event-based asynchronous pattern (around a send/receive messaging API). Is there a step-by-step guidance about how to write code for the EBAP ? Does any book cover this theme...
1
by: leno | last post by:
Hi all, I'm having this problem when i combined multiple schema's into one. The error msg is below: Unable to load schema with target namespace 'http://www.tdbanknorth.com/IFX170_TDBN' from...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.