[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C#: How to validate an XML file against an external XSD...

Posted on 2007-07-20
6
Medium Priority
?
429 Views
Last Modified: 2008-02-01
In C#, how can I pass in an XML file and an XSD (the XML file does not reference the XSD internally) and validate the XML file?


0
Comment
Question by:csullins
  • 4
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
JimBrandley earned 1000 total points
ID: 19536791
This link has a clear example:

http://aspalliance.com/941
0
 

Author Comment

by:csullins
ID: 19540515
Cool

So if my XML file appeared in a text field rather than a file

// 1- Read XML file content
        this.Reader = new XmlTextReader(XMLPath);
 
        // 2- Read Schema file content
        StreamReader SR = new StreamReader(XSDPath);

In other words, can I replace:

 this.Reader = new XmlTextReader(XMLPath);

with this:

this.Reader = new XmlTextReader(txtMyField.text.tostring());

?
 
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19540611
Not quite. Constructing an XmlTextReader with a string is only for passing a file name to the reader.
You could use
MemoryStream myStream = new MemoryStream(Encoding.ASCII.GetBytes((txtMyField.text.ToString()));

Then instantiate the XmlTextReader as
this.Reader = new XmlTextReader(myStream);

Be sure to close the stream when you are finished with it.


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:JimBrandley
ID: 19540617
When you want to check that sort of thing for yourself, just highlight the Object type, say XmlTextReader and hit the F1 key. That pops the help window and will show you about that class.

Once you drill into the members, you can see all the constructors and other public methods and properties available.
0
 

Author Comment

by:csullins
ID: 19540757
Hi Jim -

I really appreciate the help, from the link, to the explanation, to the last comment about how I cna find out for myself.  I have my laptop at work so I wasn't going to be able to figure it out until Monday... but now I know.

Chris
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19540824
My pleasure Chris. Good luck.
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

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
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

873 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