Simple Xml Validation with strings

Hello,

I have two strings;

string XmlFragment; //contains the xml document
string XsdSchema; //contains the xsd schema

I would like to validate the XmlFragment against the XsdSchema. What is 
a clean, simple way for accomplishing this?

Bye,

Ward






0
2/4/2005 10:32:28 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
653 Views

Similar Articles

[PageSpeed] 29

Try something like this:

1) Load your XsdSchema into a StreamReader
MemoryStream ms = new MemoryStream((new
Text.ASCIIEncoding()).GetBytes(XsdSchema));
StreamReader schemaReader = new StreamReader(ms);

2) Validate your XmlFragment on the StreamReader
XmlTextReader xmlReader = new XmlTextReader(new 
System.IO.StringReader(XmlFragment));
XmlValidatingReader reader = new XmlValidatingReader(xmlReader);
reader.ValidationType = ValidationType.Schema;
reader.Schemas.Add (XmlSchema.Read(schemaReader, null));

while (reader.Read())
{}
reader.Close();
xmlReader.Close();

I hope it could help.

                         Lionel.

"Ward Bekker" <ward.bekker@replacethisEquanimity.nl> a �crit dans le message 
de news: Oqo%23yTqCFHA.3368@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have two strings;
>
> string XmlFragment; //contains the xml document
> string XsdSchema; //contains the xsd schema
>
> I would like to validate the XmlFragment against the XsdSchema. What is a 
> clean, simple way for accomplishing this?
>
> Bye,
>
> Ward
>
>
>
>
>
> 


0
llaske (3)
2/5/2005 7:56:53 AM
Lionel LASKE wrote:
> Try something like this:
> 
> 1) Load your XsdSchema into a StreamReader
> MemoryStream ms = new MemoryStream((new
> Text.ASCIIEncoding()).GetBytes(XsdSchema));
> StreamReader schemaReader = new StreamReader(ms);
> 
> 2) Validate your XmlFragment on the StreamReader
> XmlTextReader xmlReader = new XmlTextReader(new 
> System.IO.StringReader(XmlFragment));
> XmlValidatingReader reader = new XmlValidatingReader(xmlReader);
> reader.ValidationType = ValidationType.Schema;
> reader.Schemas.Add (XmlSchema.Read(schemaReader, null));
> 
> while (reader.Read())
> {}
> reader.Close();
> xmlReader.Close();
> 
> I hope it could help.
> 
>                          Lionel.
> 
> "Ward Bekker" <ward.bekker@replacethisEquanimity.nl> a �crit dans le message 
> de news: Oqo%23yTqCFHA.3368@TK2MSFTNGP10.phx.gbl...
> 
>>Hello,
>>
>>I have two strings;
>>
>>string XmlFragment; //contains the xml document
>>string XsdSchema; //contains the xsd schema
>>
>>I would like to validate the XmlFragment against the XsdSchema. What is a 
>>clean, simple way for accomplishing this?
>>
>>Bye,
>>
>>Ward

Hi Lionel,

Thank you very much for the example. I'll try to implement it.

Bye,

Ward
0
2/7/2005 6:42:46 AM
Reply:

Similar Artilces:

AutoComplete from Validation List
I need to add a column to a worksheet that shows the Country of Orgi for a product and that county's assigned computer code (Ex. Unite States - 10001). I have a list of counties and correspoding codes bu the list to so long (300 countries) that I would like to be able t type in "United" and have the cell auto complete the rest. Otherwise have to scroll through a drop down menu of over 300 entries. Any suggestions would be appreciated. Thanks -- Message posted from http://www.ExcelForum.com Debra Dalgleish shows a way to use two data|validation cells. The first cell can s...

Validating Xml with an with the longer form of EndElement fails
' First create Xml document Dim oXmlDocument As New System.Xml.XmlDocument oXmlDocument.LoadXml("<Trees><Oak TreeType=""deciduous""></Oak></Trees>") oXmlDocument.Save("Trees.xml") ' .NET save xml document with spaces <Trees> <Oak TreeType=""deciduous""> </Oak> </Trees> ' Because there is spaces between <Oak ...> and </Oak> validation against an xsd schema will now fail. Complains about white space. ' However, if the endelemnt </Oak> was removed...

Simple graph
I have a chart with zip codes and a population rate. ZIP RATE 80001 2.34 80002 1.23 80003 1.23 I want to make a chart that has the rate on the x axis and the number of times that rate occurs on the y axis. | | | * | | * |_________________________________ | | 1.23 2.34 Thank you. I will assume the ZIP and RATE stuff is in A1:B200 (labels in row 1) Label in G1 to read RATE (but leave it empty for now), label in H2 to read COUNT Make a list of rates in G2:G20 (say) In H2 =COUNTIF($B$2:$B$200,G2) Copy down the row Select H1:G20 and make a...

DataSet to XML
I have data coming from SQL Server and need to write out some XML. I have a schema(xsd) for this XML file. Right now I am bringing in the DataSet and writing out the elements and attributes myself using xmltextwriter to match schema without really using the xsd at the time of writing. The file I create validates but I was wondering is there a better way? I see things like inferschema method off of dataset, can this be used? How do you map columns in a dataset with elements and attributes in the schema? I know dataset.WriteXmL will write XML but that match my schema. Appreciate any help! Tha...

Excel to XML conversion in Excel 2003
Does Excel 2003 have the ability to convert Excel spreadsheet into XML with custom DDT? I know that Excel 2003 can convert Excel data into XML, but I do not know if I can import my own DDT into Excel. thanks Hi Hao, > Does Excel 2003 have the ability to convert Excel > spreadsheet into XML with custom DDT? I know that Excel > 2003 can convert Excel data into XML, but I do not know if > I can import my own DDT into Excel. thanks Yes. You can attach a custom XML schema to a workbook and map each element in the schema to a separate cell or list in the workbook. Once y...

Simple help with implementing Outlook-like GUI
Hi All. I am an experienced unix programmer who sometimes has to do something in the windows world, and always has newbie-questions. Basically I want to write an application program that looks like outlook in that it has nice icons down the left hand side that choose the content of the main area in the right hand side. So I started the MFC App wizard, and got me a SDI program with a CLeftFrame (CTreeView) and a CMainFrame (CFrameWnd). Then I prepared the following snippet of code to draw the buttons: // Create a pushbutton CBitmapButton* pmyButton; pmyButton = new CB...

Simple Simple Simple
Just started Excel (again) and need to make an easy speadsheet fo calculating square inches. Column A: Height Column B: Legnth Column C: Total Tags per 16 x 24 Column D: Cost per tag Figures I know: each sheet cost me $9.98. each sheet is 16 x 24 inches What I want to do is enter the Height, enter the Length and have th total (sum) be entered into columns C and D. I can't believe I forgot how to enter formulas. Any help will b appreciated. Thank you, Crai -- Message posted from http://www.ExcelForum.com Hi Craig, One Way, might be better ways but this'll work: List the colou...

Simple hack to get $500 to your home. 06-05-10
Simple hack to get $500 to your home at http://uknews.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. ...

xml/rid question
I am using Visual Studio 2003/C# I created a new xml schema/xsd file (Project Create new item->Dataset) I then added Elements to the schema using the designer From the toolbox I then created an instance of my dataset. I then dropped a grid (Infragistics UltraWebGrid) onto my form, and bound the grid to my dataset. At runtime, I configure the columns of the grid, get some records from the Employee database (SQL Server2k), and add some rows to the grid. The user then enters some data into various cells of the grid. I am now ready to update the database with the contents of the grid. What ...

Simple Query Wizard hangs
I am using Access 2003 When I initiate the "Simple Query Wizard", I am presented with the first screen - "What fields do you want in your query" When I click on the pulldown list to select a table, I get the following message: "The expression On Get Focus you entered as the event property setting produced the following error: the text you entered isn't an item in the list * the expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]. * There may have been an error evaluating the function, event, or macro&q...

Calendar in Cell Validation
I want to implement a cell validation such that when the user attempts to input a date, a "list" box-like functionality pops up that has a calendar and the user may then choose the date by picking with the mouse How would I implement this? Thanks Jerry Try the following Web site. http://www.fontstuff.com/vba/vbatut07.htm This site's author covers this in a tutorial, but also provides downloads. Mark <jerry.ranch@pioneer.com> wrote in message news:2r9t51pjmumjk7rjpopo7fuamg81gqkljq@4ax.com... >I want to implement a cell validation such that when the user attempts &g...

I Need a Simple Sales Software
Hello, I am looking for software to keep track of my prospects, customers, and the notes of the sales process. I spend about one hour a day on sales and marketing, so I prefer a simple and inexpensive software. Maximizer, Outlook, Act, and Goldmine seem made for the full-time professional salesperson. Please let me know if what I am looking for exists. Best Regards, T.I. ...

Make it more simple or intuitive to do simple things
I appreciate the fact that applications are becoming more versatile and able to do things that we hardly thought possible in the past but I feel that in this added complexity you are losing sight of the need to do simple things easily without resorting to trial and error or consulting "help" which often anyhow doesn't lead one straight to the solution! An example is how to produce a chart with a series of months i.e Jan Feb Mar etc appearing on the X axis. This is no doubt something that resulted naturally in the first versions of Excel charts or in a competitor's ea...

Urgent! What is wrong with this XML file
Hi, I have generated this XML from my application. But, when I open this XML, it is throwing error. Please help me to resolve this. <?xml version="1.0" encoding="utf-8" ?> <searchResults> <totalhits>16916</totalhits> <searchquery>*</searchquery> <timetaken>TIME TAKEN</timetaken> <resultsperpage>10</resultsperpage> <currentpage>CURRENT PAGE</currentpage> <totalpages>1692</totalpages> <content> <title>Web Title...</title> <reference>http://www7.hd...

Converting access tables to XML for use in .NET web app
I need to access tables in an .mdb file and convert them to XML for use in my ..NET 2.0 web application. Can anyone point me to any tutorials or references on how to accomplish this? (Note: I am using VB) Thanks! ...

Simple public folder permission problem
I have a public task list folder. However even though I have given everyone "Author" priviledges and full control of the directory, users cannot update the tasks (although they can create new ones). The changes to tasks get reset to their original values. Where should I look to fix this problem? Brian How did you grant Author Access, via Outlook or ESM? What do you meanyou gave them full control of the directory? "Brian Taylor" <taylorb@newsgroups.nospam> wrote in message news:e2hwumGrEHA.1160@tk2msftngp13.phx.gbl... > I have a public task list folder. Ho...

XML Serialisation problem
Hi, We are serializing objects to an xmlfile that is validated against a schema. For this schema the elements are serialized in the wrong sequence. Does anyone know how I can let the serializer sequence the object members in the order required by the schema? thx Patrick De block These threads might help: http://groups.google.com/groups?threadm=ucB6uaVcCHA.2532%40tkmsftngp09 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=%234BfF5VzCHA.2232%40TK2MSFTNGP09 (Complete thread) "Patrick De Block" <patrick.de.block@pandora.be> wrote in messag...

What is simple text?
When creating a custom list that includes a column of accounting formated data, I get an error message that 'fields without simple text will be ignored'. The result is all other data except the accounting formatted data. Help!!!! I suppose it means without the currency symbol and thousands delimiters. On Fri, 8 Apr 2005 11:01:04 -0700, TexMas <TexMas@discussions.microsoft.com> wrote: >When creating a custom list that includes a column of accounting formated >data, I get an error message that 'fields without simple text will be >ignored'. The result is ...

simple question
Okay, I have a very simple question. Where do the old posts go after they run off the last page of this newsgroup? Sometimes I would like to refer to a post that I remember seeing in October, but is no longer on the current section. The search function seems to only search current posts as well. If anyone has some input please email me at joep@siboneylg.com Thanks kindly. have you tried google groups, they keep archived old posts: http://groups.google.co.uk/groups?q=microsoft.public.greatplains&hl=en "Joe Proehl" <joep@siboneylg.com> wrote in message news:099701c5...

"A valid number is required"
Hi there, I have a very strange problem on one of my users. I've created a DOT file with fields. Some fields are type Number with the format #.##0. The strange thing, is that on just one user, the filling of those fields if the user inserts a more than 4 digits number, it gives the message "A number is required" Why is this happen just on that user, that has the same Office and Windows version like the rest of the users ? Is there any altered configuration ? Regards, If you create a DOT file, doesn't that mean you're working in MSWord? You may want to post in one...

Simple Macro is not so simple
Hi all, I am trying to record a macro which will automatically perform the insert > comment function to a selected cell. Should be easy right? Alas no Danny There's sample code on my web site, for inserting comments: http://www.contextures.com/xlcomments03.html Aardvark wrote: > Hi all, > > I am trying to record a macro which will automatically perform the insert > > comment function to a selected cell. Should be easy right? Alas no -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html Wow! Nice one :-) Thank you M...

(Error 1004) Object Defined Error ...simple code
I have the following simple simple code: Dim s as String s = WeekdayName(1) ' Causes Error 1004 Why would the above call to "WeekdayName(1)" suddenly cause an Object Defined Error?? My program has been working nicely for awhile, but now all of a sudden it halts at the above line??? What the heck is going on??? Robert Crandal Hi Robert, It works fine for me. However, checking out Help, the first day of week parameter is supposed to default to Sunday (or 1) as the first day of the week but it appears to default to zero. Tested in xl2002 and x...

Validation not occuring
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation event handler is not called even when the XML should valid properly against the schema. Obviously I'm missing something. Can anyone help? Thanks, Matt. ---------- // sXsdFileName, sXmlPath, and sXsdPath contain valid paths. System::Xml::XmlReaderSettings^ readerSettings = gcnew System::Xml::XmlReaderSettings(); readerSettings->Schemas->Add( sXsdFileName, sXsdPath ); readerSettings->Va...

How to receive and send XML using .NET
I would like to receive XML over the internet (via HTTP Post or SOAP), read it, perform some server side operations, and send back an XML response that would depend on the contents of the XML received. Seems simple, but I cannot find a good example of how to do this. In the Microsoft "Developing XML Web Services.." book, there is a nice discussion of XML and how to load it from a file and directly in code as a stream/string, but no mention of how to get or send it via HTTP. In an HTTP Post, how do I write my XML to the header and how do I read it? Also, is it necessary to use...

vb--simple simple
hi, anyone know how to copy a combobox selection to a specific cell b using vb code in a command box -- Message posted from http://www.ExcelForum.com i cant see this in the userform. i know you can do this with a normal combo box which is not in a for but lost when in a userform -- Message posted from http://www.ExcelForum.com What's a "command box"? Can you give an clear example of what you want to do? -- Jim Rech Excel MVP "stevieh >" <<stevieh.16v8yw@excelforum-nospam.com> wrote in message news:stevieh.16v8yw@excelforum-nospam.com... | hi, | |...