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
1953 Views

Similar Articles

[PageSpeed] 53

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:

FRx 6.7: Accounts Not Displaying In Row File
I have successfully created Financial Statements for two of our three companies. However, I’m having a problem with the third one. In creating the row file, I specify a range from account 30000 through 99999. Most accounts show up in the list. Some don’t. The following account string will be my example of an existing account, with a balance, that does not show up in the row file: 00000-30035-00000 (30035 is the main account) If I manually insert a row into the row file, type in the description, and click the down arrow for the GL Link, the account does not display in the drop down. Ho...

Private EDB file
Hi, I am working with a client that has SBS2003 and is using Exchange 2003. There are 14 mailboxes with a total size of 4.5GB. When I look at the file size of the private edb, it is at 17GB. Why is there such a discrepancy and what can I do to shrink the size of the edb, so that I don't run into size limit problems. Thanks, Tom you need to perform offline defragmentation on the databases to also take a look at this site for updates SBS http://www.microsoft.com/WindowsServer2003/sbs/downloads/presp1.mspx http://consultusa.us/index.php?itemid=19 http://support.microsoft.com/kb/192...

Transferring files #4
I have re-installed all my software on a new hard disk. (The old hard disk still installed and working). How do I transfer my diary from my old disk to my new disk please? Thanks. Bill Ridgeway Hi Bill, maybe this sites could help: http://www.slipstick.com/config/backup.htm http://www.slipstick.com/config/movepst.htm -- Oliver Vukovics Share Outlook without Exchange: Public ShareFolder Share your contacts, calendars or e-mails http://www.publicshareware.com "Bill Ridgeway" <info@1001solutions.co.uk> schrieb im Newsbeitrag news:edlvnj$9gr$1@news8.svr.pol.co.uk... &g...

Suppress "Missing XML comment" warning during compile?
I use XML comments around most of my class libraries public property and methods, for example: /// <summary> /// blah blah /// </summary> However I have a few dozen public constants as well as a few properties and methods that I do not want to provide any XML comments for. This generates errors like this: page3.cs(43,25): warning CS1591: Missing XML comment for publicly visible type or member 'test.testclass.constants.CONST_RECNOW' Is there a way I can have the .NET complier (C#) suppress these warnings? Ideally I'd like to indicate somehow in the source that these ...

Access2000: Setting a filter to a subform
Hi I have an unbound form fmMain. On this form I have some combo boxes (cbbAGroup, cbbAStatus, cbbAStore), and a subform sfAssets, which is based on form fmAssets. The source for form fmAsset is a table tblAssets with fields AssetID, AGroup,...,CurrStatus, CurrStore, ... etc. For subform sfAssets is defined the link cbbAGroup-->Agroup, i.e. the subform always displays assets of the single group, determined by combo on fmMain. Now 2 other combos must determine a filter condition for form fmAssets. The filter condition will be (in simplified form, not the real formula) Iif(cbbAStatus=...

Importing .VCS file
When I attempt to import a .VCS file created by Lotus Organizer 6.0 Outlook gives me an error message stating that I do not have the rights to import such a file. I was able to import one calendar event that was saved as a .VCS file. Any help would be appreciated. Thanks. ...

trouble sending large files
I am having trouble in outlook express 6 sending large files. When I say large I mean a half meg or larger. The send bar will go to about 99% and then just stay idle at that point. Eventually I get an error message that says it has stopped responding and asks what I would like to do. Continue trying or stop. No matter which I pick it stays the same. Then I find out it sends multiple copies for each time I try to stop it. This can be very annoying to my friends who have a dial-up. Any suggestions? Are your using a dialup or broadband (cable/dsl) account? If broadband, are you behind a...

Merging text files with excel
Hello All. How can I merge several text files with the same format into one Excel sheet in one go ? I am importing them singly but it would be much better to merge them together before opening. Many thanks for any help ! Maybe you can use some old DOS commands. Shell to a command prompt and issue an old DOS command to concatenate the Text files. Windows start button|Run (or flying windows r as a shortcut!) win98: Command WinXP/NT: CMD Go to that folder: C: (to change to that drive) cd\myfolder1\myfolder2\myfolder3 to change to that folder copy *.txt All.Files Ren All.Files All....

Bulk Extract Embedded Files
Word 2003 on XP Is there a way to extract embedded files all in one go? Like the image file extraction process described in http://www.gmayor.com/extract_images_from_word.htm but for embedded files? Many thanks DeanH Found the following for extracting embedded word files. Haven't tried it though. Sub ExtractFiles() ' ' ExtractFiles Macro ' ' Dim shape As InlineShape Dim folderName As String Dim a As Document folderName = Replace(ThisDocument.Name, ".", "_") MkDir folderName For Each shape In ThisDocument.InlineShapes ...

Problem importing data from text file
Hi, I have a comma delimited file that has twenty column names followed by six rows of data. I am trying to import this into Excel. When I do this, the data imports entirely into row one. It does import into difference cells but there is one row with 120 cells of data. I was expecting it two "Wrap" and start importing the data into cell A2. Can anyone help with this? How do I show the break between column headers and data? Thanks, Chuck ...

convert money plus files into money 2007
I downloaded the new trailversion of money Plus. Now I do not like the new version of money Plus . I had money 2007, but now I cannot convert my money files from the Money plus version into the Money 2007 version. What can I do? When you converted your M2007 file to M+ there was a screen message telling you that it had made a backup. You *of course* made a note of this!?!? If you didn't go and look for a file *.m16. Rename this as *.mny and reinstall M2007. Of course you will have to reinput all transactions since the conversion. -- Regards Bob Peel, Microsoft MVP - Money F...

Shared file doesn't share
We have a shared file that now gives us a message that someone else is in the file and do we want to open as read only. Anybody know what might cause this? Well... YOu can set the file to read-only by right clicking on the file and choose the properties dialog box to avoi getting this error message. THis will prevent you from modifying the file kanan ...

can outlook be set to not display pictures
When outlook, (office 2000) is downloading messages, I have the preview pane open. As probably everyone gets, I am getting multiple messages that are spam, and mostly sex crap with naked pictures embedded in the message. So once the message is clicked on, the preview pane shows whatever is in the message, including the pictures. I wouldn't complain if they were half decent looking, but that's another story. Is there a way to not display pictures in the preview pane? I've got 2003 so not sure if it's the same in 2000 - but.. Tools>Options>Security>Change Auto...

Setting excel to landscape and setting print area from access
I have an excel file that I create from access and I was wondering if there is an easy way to set the page setup to landscape and to set the print area width from access. Is there an easy way to do this? I created a macro with the excel macro recorder but I am not sure if I can somehow use this code to have access do this. Any direction on this would be appreciated. thanks [code] With ActiveSheet.PageSetup .PrintTitleRows = "" .PrintTitleColumns = "" End With ActiveSheet.PageSetup.PrintArea = "" With Active...

How do I create a pdf or txt file?
I need to get my word files that save as (.doc) to a (.txt or .pdf) file. Is there anyway to do that without the software? This is a multi-part message in MIME format. ------=_NextPart_000_0012_01CA7C42.604BDA30 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hi Deana, This newsgroup is specifically for matters dealing with Microsoft = Project. I suggest you try to find a more appropriate newsgroup that = deals with Word problems. However, from the Save As... dialog, at the bottom is Type selection = which should ha...

How I can set highlighted active cell in row & colmun cross
I want to set active cell highlighted in row & colmun cross as it was possible in Lotus 123. Is it possible? if yes, how is it? Option Explicit '---------------------------------------------------------------- Private Sub Worksheet_SelectionChange(ByVal Target As Range) '---------------------------------------------------------------- Cells.FormatConditions.Delete With Target With .EntireRow .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE" With .FormatConditions(1) With .Borders(xlTop) ...

Intermitent file problem?
Running Outlook 2003 and from time to time the frame with the Inbox list of emails and viewing pane will be blank with an error message stating the system is busy and that perhaps something else has it tied up. How can I debug and fix? ...

How do I delete excess pages from a file?
I'm sending a file that I only need one page in, but the recipient has told me that it has 1700 pages. I'm using Excel and sending with outlook. What does the file look like from your end? Has it got 1,700 pages or just one? "deejai03" wrote: > I'm sending a file that I only need one page in, but the recipient has told > me that it has 1700 pages. I'm using Excel and sending with outlook. In Excel jargon a File is a workbook. A workbook can have multiple worksheets. A worksheet can have multiple pages when printed. What exactly is the...

can only see one page of a multiple page publisher file
today can only see the first page of a file in publisher....checked the attributes removed the read only....could not remove from overall i.e. my documents...can pull up on another computer via network and see all....so file appears to be okay...can also print all pages, but can only see and work with page one...HELP.....AND A BIG THANKS TO WHOMEVER!!!! What happens when you try to click on the other pages? Do you have the status bar turned on? (View - Status bar) -- JoAnn Paules MVP Microsoft [Publisher] "CON" <CON@discussions.microsoft.com> wrote in message news:...

File format is invalid
I have a file that I update and save daily. yesterday when I went t open it I got the following message: File Format Not Valid. This pop up in middle of the screen. the only option it gives me is a butto that says OK. I have tried to recover an old version of the file usin the windows recovery tool but I keep this file on an external driv which it does not recover. Any help with how to get this file bac would be greatly appreciated. Pau -- pserra ----------------------------------------------------------------------- pserra2's Profile: http://www.excelforum.com/member.php?action=ge...

can't save files in Office2001 running on OSX
I'm running Office2001 for mac on my OSX system through OS9. The applications work fine until I try to save. "Save", "Save As", and "Save as Web Page" all make the windows blink as if it's going to do something, but then nothing else happens--no save window, no files on my hard drive. Any ideas why this might be happening, or how I can fix it? You thoughts are greatly appreciated! Jake ...

Task reminders set for a time/date AFTER due date
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: Exchange Hi - <br> As a default, whenever I create a new task, the &quot;reminder&quot; is one day AFTER the event's default &quot;due date&quot;. <br> i.e., <br> Start Date: Mar 1 2010 <br> Due Date: Mar 1 2010 <br> Reminder Date: Mar 2 2010 (Herein is the problem!) <br><br>When I manually update the event's due date (i.e. Mar 1 --> Mar 15), the Reminder date automatically changes (i.e. Mar 2 --> Mar 16). How can I fix...

Setting up Outlook sync with RPC over http
I'm trying to setup my Outlook installation to sync with my school Outlook servers. The IT administration has hinted that it's possible and some students have figured out how to accomplish this, but they don't want to support it. Supposedly it's a nightmare to support the myriad hardware and software configurations of 450 students (doesn't sound so large does it?). The only supported means for accessing our email accounts and utilizing the calendar function of Outlook etc. is via webmail. Webmail address: https://webmail.osumc.edu/exchange/ The faculty are ...

how to set up outlook for OUT OF OFFICE REPLAY
I have a POP3, which dosn't support out of office replay. How or who do I contact to chage this so I can have Out of office replay contact your email administrator and ask if you are using exchange server. If not, you need to create rules to replicate the out of office action. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips: http://www.outlook-tips.net/ Outlo...

Transfer from file to document very slow
I take about 40 seconds for the document to come up on screen This also happens in Word It is impossible to provide a concrete suggestion with so little information. The slow opening of a file could be due to any and all of the following as well as many other factors. Insufficient RAM to hold the large file leads to numerous time-consuming saves to virtual memory. A virus protection program to blocking the opening of the file until it has completed a virus threat check on the file. Other applications are hogging machine resources. A potential resource hogging application may be a ...