How do I set the schema for an XML file?

Hi;

I'm sure this is straightforward but I can't find it. How do I pass a
schema file with an XML file when I load the xml file? I need this
mostly for an XPathNavigator object I create.

??? - thanks - dave

david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
0
thielen (152)
11/17/2009 6:07:16 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
1848 Views

Similar Articles

[PageSpeed] 21

David Thielen wrote:

> I'm sure this is straightforward but I can't find it. How do I pass a
> schema file with an XML file when I load the xml file? I need this
> mostly for an XPathNavigator object I create.

Create XmlReaderSettings that has any schemas and validation option, 
then load the XML with an XmlReader created with those settings e.g.

             XmlReaderSettings xrs = new XmlReaderSettings();
             xrs.ValidationType = ValidationType.Schema;
             xrs.Schemas.Add(null, "schema1.xsd");
             // add further schemas as needed e.g.
             //xrs.Schemas.Add(null, "schema2.xsd");
             // add ValidationEventHandler if you don't want an exception
             // in the case of validation problems e.g.
             //xrs.ValidationEventHandler += new 
ValidationEventHandler(xrs_ValidationEventHandler);

             XmlDocument doc = new XmlDocument();
             using (XmlReader xr = XmlReader.Create("input.xml", xrs))
             {
                 doc.Load(xr);
             }

You could also pass such an XmlReader to the XPathDocument constructor, 
in case you work with XPathDocument and not XmlDocument.

If you already have an XmlDocument and want to add type annotations then 
use the Validate method
http://msdn.microsoft.com/en-us/library/ms162371.aspx

See also http://msdn.microsoft.com/en-us/library/w5aahf2a.aspx

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1777)
11/17/2009 6:26:58 PM
On Tue, 17 Nov 2009 19:26:58 +0100, Martin Honnen <mahotrash@yahoo.de>
wrote:

>David Thielen wrote:
>
>> I'm sure this is straightforward but I can't find it. How do I pass a
>> schema file with an XML file when I load the xml file? I need this
>> mostly for an XPathNavigator object I create.
>
>Create XmlReaderSettings that has any schemas and validation option, 
>then load the XML with an XmlReader created with those settings e.g.
>
>             XmlReaderSettings xrs = new XmlReaderSettings();
>             xrs.ValidationType = ValidationType.Schema;
>             xrs.Schemas.Add(null, "schema1.xsd");
>             // add further schemas as needed e.g.
>             //xrs.Schemas.Add(null, "schema2.xsd");
>             // add ValidationEventHandler if you don't want an exception
>             // in the case of validation problems e.g.
>             //xrs.ValidationEventHandler += new 
>ValidationEventHandler(xrs_ValidationEventHandler);
>
>             XmlDocument doc = new XmlDocument();
>             using (XmlReader xr = XmlReader.Create("input.xml", xrs))
>             {
>                 doc.Load(xr);
>             }
>
>You could also pass such an XmlReader to the XPathDocument constructor, 
>in case you work with XPathDocument and not XmlDocument.
>
>If you already have an XmlDocument and want to add type annotations then 
>use the Validate method
>http://msdn.microsoft.com/en-us/library/ms162371.aspx
>
>See also http://msdn.microsoft.com/en-us/library/w5aahf2a.aspx

thank you!!!

david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
0
thielen (152)
11/19/2009 4:41:29 PM
Reply:

Similar Artilces:

Populate Exchange public folder with contacts from txt file
I have just set up a new Exchange 2003 server, and i would like to make available to all users a number of external email contatcs that i have in a text file. The process of importing contacts to Public Folder should be repeated periodically (let's say weekly), and should not be made by manual user interaction, but programmatically. Being new to the Exchange word I cannot find any way to do this, and all the hints i did find involve the use of the outlook client with cut&paste or drag&drop of contacts. Any help appreciated Best regards Francesco I suppose a script could do...

Setting up a Macro
What I want to do is record a macro and then have a button on the spreadsheet to click that will run the macro. The macro itself will cause a Solver to be run so it only has to open the Solver and input 2 predetermined cells and one predetermined hard number. I can start and stop a macro recording and set a hot key to run it, but when I run the macro its stops and tries to debug itself unsuccessfully. I know there are only a few steps to pull this off, but I can't seem to get it right. Any help would be appreciated. Post the code you are trying to run and indicate which line is throw...

How to Write Memory Bitmap into BMP File?
In a MFC dialog, I add a button(IDC_BUTTON1), and the corresponding message function is: void CHhhhDlg::OnButton1() { // TODO: Add your control notification handler code here CClientDC clientDC(this); CDC memDC; memDC.CreateCompatibleDC(&clientDC); CRect rcClient; GetClientRect(&rcClient); CBitmap membitmap; membitmap.CreateCompatibleBitmap(&clientDC, rcClient.Width(), rcClient.Height()); memDC.SelectObject(&membitmap); for (int x = 0; x < rcClient.right; x ++) { for (int y = 0; y < rcClient.bottom; y ++) { memDC.SetPixel(x, y, x < y ? RGB(255, 255, 0) : RGB(...

can not see files
I am using win xp sp3. I just put a new hard drive. I re-install o/s and reinstalled docs& settings from a external hard drive. I am trying to use macrium and make a bart pe disk. All of my files are hidden. IWhen i download something to my documents if i go directly to my documents i can see them. If i go into windows explorer they are not visable. How can I make them not hidden? I went into folders and clicked show hidden folders. Thank you, Phil If I click on my docs from the start menu i can see all my downloads, when i go into explorer, on the left side (folder side) t...

ATTxxx.dat files
Hi, my father in law is receiving mails in his non-outlook mail client with ATTxxx.dat files with the xxx being other digits. The mails are send from an Outlook client. The mail header is referring to another attachment, a bigger file. From what I've read on the net Outlook splits up the bigger files into the .dat files and re-assemblies them when receiving. But since this is a non-Outlook client it doens't reassemblies them! I also read something about rich text so this wouldn't happen but my question is ... is there a way to reassemblie the files manual ? Grtz, Michel ...

Reducing File Size???
I have the same file performing the exactly the same thing but one is double the other. It appears to me that the more I work with the worksheet the bigger the size of the file. how can I remove this redundant memory space? Cheers Jio, You probably have formatted or otherwise used some rows below or columns to the right of your data. On the bloated workbook, select the sheets individually and press Ctrl + End. If the last row and column is well below where you think it should be, you'll need to delete the empty rows and columns. Check here for an example of how to do this both manua...

How To Find and Delete Duplicate Files? http://DuplicateFilesDeleter.com
How To Find and Delete Duplicate Files? http://DuplicateFilesDeleter.com http://DuplicateFilesDeleter.com is an innovative tool that can recognize duplicate audio files even if they are stored in different file formats and not marked with ID3 tags. It will find fast all similar or exact duplicate audio files in a folder and its sub folders. Unlike common duplicate file finders it will actually "listen" to your music and can recognize a song even if it is saved in different file formats. Supports MP3, MP2, MP1, MPA, WAV, OGG, AIFF, AAC, MP4, FLAC, AC3, WavPack (WV), Musepack (MPC) an...

What is an .swp file? And why is it so huge?
131,072kb And is it a friend or foe? It's a file that Windows creates. Think of it as a way to leave files out on the desk so you can find them easier. When you reboot, the file will shrink, then grow again as you work. In other words, it's normal. Melissa "Carol" <carol@willapabay.org> wrote in message news:129cf01c3f6a8$b3e2f500$a001280a@phx.gbl... > 131,072kb > > And is it a friend or foe? Carol wrote: > 131,072kb > > And is it a friend or foe? What has this to do with Publisher?! If a file is large enough to exhaust your computer'...

Can't Open or Corrupt Report Money Plus Deluxe File
When I want to export a report using the .CSV format, I get an error that the file is corrupt or the file type is wrong. Thus the file cannot be opened in MS Spreadsheet. After a little investigation, I found that my version Money deluxe (17.0120.1415) is generating a corrupt CSV file. The work around to the issue is to open the csv file with Notepad.Go to the very last line of information in the file, press enter and then hold the delete key to remove and excess spaces. Save and close the file. Now the file can be opened with the spreadsheet. This error never occured when MS Money ...

Schema Location not found
Hi, In the process of Validating my Schema, having hosted them in my local server (http://localhost/DataTypes/....) I still the get the error "Unable to determine the Location of Schema" in XML Spy and in VStudio.NET. Please advice. The Schemas hosted in the Local WebServer are also visible across the network, are we missing something here? Best, Greg ...

Is it possible to set an alarm in EXCEL?
Hello, does anyone know if it is possible to set an alarm in Excel. I' working with a lot of dates in Excel and I've got one column which i called "DATE OF NEXT ACTION" and at that date I'll need to call specific client. I know that I can filter the data on that column. But is there a way t set Excel so that something pops up on the screen? Or any other possibility that Excel checks the dates in that column an makes me aware if today's date is the same as the one in the column? If not, is there another software that can do that? Thanks so much for any help yo...

Customizing Views in OL2003 across a "Personal Folders" folder set
My company has migrated to Outlook 2003 and I would like to make some changes to the new Default Views. I have read the tips at outlook-tips.net and gone through this group in some detail but have not been able to accomplish my goals I have a bunch of folders saved on my local drive under "Personal Folders" which is on the same tree level as the main mailbox. I would like to 1) Disable Grouping 2) Disable the Reading Pane For 1) I tried View->Define Views->... per outlook-tips.net but it did not work across the subfolders in the Personal Folders directory. I also tried dis...

Data file conversion M05 to M04
I am trying to go back from M05 to using M04. Is there utility that converts my M05 data file to M04 format? When you converted to M2005 it made a backup of your M2004 files as *.m12 and told you where it put it (usually same place as .mny). Rename this as *.mny and open with M2004. You will of course have to catch up all transactions since you converted. -- Regards Bob Peel, Microsoft MVP - Money For UK tips & fixes see http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny. For wishes or suggestions see http://register.microsoft.com/mswish/suggestion.asp or for UK wishes ...

Organizing .pst files
Does anyone know how to set Outlook to organize the files non-alphabetically? I want to have the folders that I use most at the top, and have other folders further down the list, however, Outlook won't let me organize all of the folders in any way other than alphabetically. You might want to read Microsoft Article 198469. I had to go this way to rename my Folders and keep the ones I like on top. Hope this helps Wes >-----Original Message----- >Does anyone know how to set Outlook to organize the files >non-alphabetically? I want to have the folders that I use ...

Win32 Static LIB Project (.dsp file anathomy)
I have Win32 Static LIB Project and something very strange happen. I have this in my .dsp file: SOURCE=..\..\src\xsec\xenc\impl\XENCEncryptedTypeImpl.hpp # End Source File # Begin Source File SOURCE=..\..\src\xsec\xenc\impl\XENCEncryptionMethodImpl.cpp # End Source File # Begin Source File SOURCE=..\..\src\xsec\xenc\impl\XENCEncryptionMethodImpl.hpp But, when I save it using VC6, I got this: SOURCE=..\..\src\xsec\xenc\impl\XENCEncryptedTypeImpl.hpp # End Source File # Begin Source File SOURCE=..\..\src\xsec\xenc\impl\XENCEncryptionMethodImpl.cpp DEP_CPP_XENCENCR=\ "..\..\src\x...

how set view>zoom>75% for always
Thanks for any help. My Excel zoom is set for 100%, automatically. I would like to set it for 75% automatically, is there a way to do that? I looked in Tools>Options but couldn't find anything. Thanks very much. The Zoom factor is a setting that applies to each worksheet and window individually, and is saved with the workbook. So any existing worksheets/windows will already have their zoom and there is no overriding setting that will change it. You could change it manually or through a macro and the new zoom will always be there for that window. If you want all worksheets in ...

How to set Outlook 2000 Default font size
I have to use Microsoft word as my default Message editor in Outlook. How can I get my way to make Font :Arial Text Size 18 as my default whenever I compose and reply a mail. ...

Loads@Sstartup ? C:\Program Files\Microsoft\Office Live_Search E_P
When I restart my computer, this window loads to desktop? C:\Program\Microsoft\Office Live_Search Enhancement Pack. If I do a selective startup withmsconfig, and take the checkmarks out of: WKsSb and wkfund, then the above window does not load? I'm thinking there is something wrong, something missing, or something that is not setup or installed correctly? Thinking about unistalling: Windows Live ID sign-in Assistant, Window Live Upload tool, and then reinstalling them; unclear on how to proceed. Please advise. Kevin, None of this is Microsoft Office related - ...

How to recover & re-establish deleted Outlook Express DBX files
I apologize for posting this twice. I forgot to include an email address. I accidently deleted my Outlook Express dbx files. I recovered the files back. However, I do notice that I have DBX, IDX, and MBX files. Next, I used the Outlook Express import wizard to try to re-establish a link to these deleted files. However, the files that were imported were from a year ago. I can't seem to import my recent files. 1) The path I follow is files/import/messages. 2) Select Microsoft Outlook Express 3) I specify my location as Main Identity. I only have one identity set up. 4) Cl...

Still have file opening problem
My laptop has the following problem...click on a shortcut to or an Excel 97 file icon and Excel opens but not the file. If I open Excel and then go to File/Open....any of the files will open fine. I now have latest Zone Alarm and have removed and reinstalled Excel several times but same difficulty keeps occuring. Have also tried "unregserver/regserver" but no luck with that either. Any suggestions would be appreciated. check the properties of your icon (right click) and what do you see for filename or program. -- --- HTH, David McRitchie, Microsoft MVP - Excel [site chan...

Best way to set form's recordsource
Hi All, Just fishing for opinions here... Do you consider it a better practice to create a query to use as a form's recordsource, or do you build it from the form's properties dialog. Usually I create a query but I'm one of those anal people who fret over then number of objects in my DBs. Does it really matter, since setting from the form's properties creates a system table entry? Probably not a big deal, but I want to make sure I'm doing the right thing. Thanks & Ciao Creating a query is self-documenting. Queries are compiled and used repeatedly until ...

"Merging" .pst files
Hi I have just purchased a new PC running Windows 7 and have installed Office 2007. This will replace an old XP PC with, amongst other things, several years of emails on it (also Outlook 2007). And as the new PC has been used for a few days, there are already a handful of email messages in Outlook. I am confident enough to copy the .pst file from the old PC and put it on the new PC, but if I use File \ Open \ Outlook Data File to open the copied data file I will end up with two "Personal Folders" entries in the Navigation pane - the old, copied one and the new one. W...

Macro to auto save file using the format YYMM
Hi, I recorded a macro that automatically saves a file then change the formula in cell A1 to today's date, ie =today(), then save the file. I have a problem with the last part...is there any way I can set the macro such that the file will be saved as "c:\YYMM ABC" where 'YYMM' is the format of the date (probably can be taken from cell A1) and 'ABC' is my own file name? Thanks! You can get the date right in the code: dim myFileName as string myfilename = "C:\" & format(date,"yymm") & " ABC.xls" activeworkbook.saveas fi...

Why can't open excel files with MRU file links
Hi, Sometimes when I try open excel files with most recently used document link, the file can't be opened. As I place the mouse pointer at windows status bar, I just see the pointer plus a funnel but that funnel never goes off. I need to reboot my windows ME OS to solve the problem (sometimes I need to boot it several times to get problem solved). The problem will not happen if I launch excel first then open the document from its file menu. The described problem happens more frequently when I try to open excel document just after my ME boots up. I would like to ask is there anything ab...

XML and Excel!
Hello! I need a XML-Export for my Software. Now I have created some test files, which can be read under XML Notepad or Internet Explorer whitout any error. But if i want to open the file under Excel, i get the following problems: 1.) Data fields with only numbers are displayed twice. 2.) The data fields where sortet in alphabetical order automatically. I want a standard XML-File which works with every Software. Can anyone help me, or give me a hint? Thanks and greetings, christian. Sorry Christian, No such thing exists. "Christian-Josef Schrattenthaler" <NoSpam@Thank.Y...