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

Similar Articles

[PageSpeed] 10

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:

setting font size to decimal number
Hi all, In the CFontDialog I am not able to set up decimal numbers, like 7.5. It works in MS Word (on the same box, the same font). Getting message "Size must be a number." Any ideas? Thanks in advance! Vaclav Hi Vaclav: > In the CFontDialog I am not able to set up decimal numbers, like 7.5. > It works in MS Word (on the same box, the same font). > Getting message "Size must be a number." > > Any ideas? Just a thought: Do you have the correct settings in the regional setting? Just check if there is jused a ',' as decimal char. HTH Alex -- ...

Import New Table; Set Primary Key As AutoNumber
I've procrastinated long enough; I'm starting to learn Access now. I know a little actually, but not much. Anyway, I'm practicing with the NWind DB. I exported each table to an Excel sheet and then tried to import each Excel sheet to a new DB that I just created. A bit silly, but it's really helping me to learn. I though I had a handle on it, but when I tried to import the 'Orders' table, it comes in kind of weird. Under Field Name 'OrderID', the Data Type is Number, but I want it to be AutoNumber so I can create Relationships. I can't seem to ...

save a publisher file as a JPG file, need to be more than default 150dpi
I am saving a publisher file as a jpg file but it only saves it with a dpi of 150, i need this to be at least 300 dpi please can someone advise how i can change and where i change the setting to do this. is it possible? thanks in advance for your help jc wrote: > I am saving a publisher file as a jpg file but it only saves it with a dpi > of 150, i need this to be at least 300 dpi > > please can someone advise how i can change and where i change the setting to > do this. Try hitting "Change" where it says "150dpi" in the Save As dialog. While you...

how do you set spam setting in outlook?
i have mail that keeps going into my spam box and i can not figure out how to stop this from happening with good email i receive? Is it going to the Junk E-mail folder or to a Spam folder? In case of the last, Outlook is not doing this but a 3rd party mail scanning tool that you have installed. If it is put there by the Outlook Junk E-mail filter, you can manage your exceptions via; Tools-> Options-> button Junk E-mail Options... -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, A...

A2002: Set Options
In Czech version of Access we have VBA EN with EN menus, help, etc. In most cases it's not a problem. But I need strings for GetOption/SetOption method. It's very uncomfortable to write down those strings from the Option tabs. Where could I get Czech tranlation of "Set Options from Visual Basic" help? Thx for the idea & the link. The translator cannot be used.The translator:Show Status Bar => Ukazovat Spolecenske postaveni Piscina (non-sence & quite funny for status bar) :-DMS Access:Show Status Bar => Zobrazit stavovy radekVladoI have removed diacritics from s...

Account setup: Test Account Setting always works
.... sending within outlook always fails. In both cases I am sending to the same external email address. Error message reads: "The operation timed out waiting for a response from the sending (SMTP) server" Now - I can understand that I may be having outbound authentication problems - but why does the test make it through then? Thanks for any help! -cf On 26 Jan 2005 13:26:38 -0800, coldfact@gmail.com wrote: > ... sending within outlook always fails. In both cases I am sending to > the same external email address. Error message reads: "The operation > timed out waiti...

PNG files not displayed correctly
An image has its picture property set to a .png file. Most of the image appears correctly, except for faded borders. These can be viewed alright in most other applications, but appear black within Access, making the image look rubbish. Suggestions? ...

problem saving to file an HTML email message
When I try to save an HTML email message to a file I get an error message saying "Out of memory or system resources - close some windows or programs and try again." I have closed all other windows/programs except Outlook and I still get this message. I can save other non-HTML messages as text without problem. This is with OL98 and WinXP. And ideas on how to save an HTML message? Thanks for any ideas. John Keith kd0gd@juno.com ...

Huge "mny" file
My "mny" file is 175MB and takes 2-3 minutes to back up. I have archived everything prior to 1/1/06 and "repaired" the file, but the file size stays the same. Any suggestions? In microsoft.public.money, ajtdawe@gmail.com wrote: >My "mny" file is 175MB and takes 2-3 minutes to back up. I have >archived everything prior to 1/1/06 and "repaired" the file, but the >file size stays the same. > >Any suggestions? Don't archive for that purpose. Don't watch so many stocks. Portfolio->More->ClearHistoricalQuotes looks like it...

File set up query.
Can i set up an excel file to open automatically on pc start up? The easiest is to use the Startup folder available in the Start Menu. To access it go to Start - Programs - Startup. You can delete or add tasks here according to your needs. They will start after Windows logon. When you start Excel, all the files that are located in the XLStart folder are automatically opened. Additionally, if you specified an alternative startup folder for Excel, every file in that folder is also automatically opened. To specify an alternative startup folder, in Microsoft Excel 2002 or Microsof...

Publisher 2003 Need to set business card to Avery 5371 setting
I need to set the print settings so the business cardd that I created will print on Avery 5371 business cards Okay.........and your question is? -- JoAnn Paules MVP Microsoft [Publisher] "Jonathan" <Jonathan @discussions.microsoft.com> wrote in message news:187615DD-9EF1-42A2-8436-78E6E6C6ACE4@microsoft.com... >I need to set the print settings so the business cardd that I created will > print on Avery 5371 business cards Page setup, business cards, click change copies per sheet, type > .5 top, .75 side, zero gaps. Avery 5371 is a standard business card s...

Have the option display summary or detail of eft file generation
The eft for Payables generates a remittance report for the vendor which includes the detail for payment, excluding the routing and account number. The eft file generation report is summarized, which does include the routing and account number. Would it be possible to add the option on the eft file generation report to print detailed or summary? That way when the invoice packets are reviewed the reviewer would only need to use one report that would include the detail from the remittance with routing and account number from the file generation report. ---------------- This post is a ...

Setting the Settings
Really quickly: How (exactly) does one get Publisher to remember the page settings I want. ie. every time I open a new document, I get centimeters, and usually, I'd prefer inches. I have not been able to find a "Save Settings" option anywhere. Can anyone help? thomas In Publisher 2000 it's Tools Options General tab Measurements unit box - select inches. OK That should do it. -- Don -------- Vancouver, USA - One of the great cities in one of the 45+ countries in America! "ThomasL" <tlammert@netcom.ca> wrote in message ne...

How do I access the files in "NetHood" folder ?
I started a "move" operation to a remote Computer in WinExplorer by dragging a local folder with files inside onto a shared folder in "My Network Places". This worked successfully without problems hundred times before. However this time the folder+files were moved into local folder D:\Documents and Settings\C\NetHood Why? Yes, the remote folder is accessible. When I click on the remote folder then I can see its remote content. And I have write access. Lets assume that WinExplorer does not recognize the remote computer: How can I tell him in such a situatio...

Best practice for setting default font settings in Word 2007
Could anyone tell me what Microsoft's "Best Practice" is for a company to change the default font settings in Word 2007? For example, if I wanted to change the default font to Times New Roman for all new documents and push this out to the company - does best practice remain the same as in Word 2003? Or has it changed with the inclusion of the default document settings and themes? Thanks so much! I am not sure how you did it in Word 2003, but in either case, I would not rely on customizing the Normal.dot template. You should create separate templates for your...

Setting network settings via Group Policy
Hi All, Have a random problem at the moment. Taken over a customer with a rouge router that keeps dishing out oddball dns entries every 30minutes via DHCP. I believe it's relaying from some old source. Until we track the problem down, what is the best way to set some DNS settings that wont change, IE set them manually via GPO. Thanks. Hello Gorge, Disable the router DHCP server and use a domain member server for DHCP or if only a DC exist use that one. Let the router do its baisc job, routing. Settings DNS servers with GPO can still result in the odd settings if ...

unable to set a record as private (activities)
Microsoft CRM v3 Customers and prospects are requesting the ability to mark a record (primarily notes and emails) as private such that only the owner and other internal party users on the record are able to open it. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http...

Setting Default Tab
When go to format tab setting, the default is always .5. I want to use .3, but when I set it to .3 (I think I am setting the default), it always reverts back to .5. What am I doing wrong? I want to stay put! This is particular aggravating in a long document like a book manuscript. I appreciate your input. Tom What version Publisher? First of all, long documents are best done in Word. You don't have to contend with text boxes. That said, the default tab setting is in the Format menu, tabs. Is this a fresh text box or one you have already typed into and now are trying to change the ta...

Excel 2002 converter for Quattor Pro (.wb3) files?
Does anyone know where I can get the converter for Quattro Pro (.wb3) files? I found one for 2000, but not for 2002. Thanks! I don't believe MS has one. Conversions Plus (separate program from DataViz, $70.00) only handles versions through 9 (QP 2000). Do you have Quattro 10? Can you open the file there and save it in an Excel format? If not, I have QP10. If the file is small enough (under 10 meg) you can email it to me and I will save in Excel 97 format and email it back to you. On Fri, 08 Aug 2003 16:04:42 GMT, "Brian Collie" <briancollie@colliecpa.com> wrote: &...

To set or not to Set...
I have a question, and I'm hoping some folks can give me feed back. I am running W2k with Ex2000 Entp. My mail box store is 24GBish. I have many users that have mail boxes over 500MB and a few that have them in the Gig range. I want to look into setting a policy that will "autoarchive" to a pst on their home drive to help reduce the size of the store. Questions 1 - What are the advantages/disadvanages of having a smaller store (besides quicker backup's and possible restores). Does it not really matter if the indivudal mail boxes get over 1Gig? Question 2 - Is ther...

pdf file conversion probs in 2007beta
When i convert an excel page into a pdf i get corrupted scripts etc ie italic changes completely. Does anyone else have the same problem? Is it because it is a beta version? Is there a cure? When using excel 2003 i have no problems. Ta It is almost certainly a beta issue but, because of an issue between MS and Adobe, it won't be in next bet or the RTM version, so you are unlikely to get a fix -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS www.nickhodge.co.uk "solecfrance" <solecfrance@discussions.microsoft.com> w...

How determine if MsProject file saved in 2003 or 2007 version?
I'm having difficulty with MsProject 2007 Professional - I think it may be because I'm switching back and forth between saving files as 2003 vs. 2007. How can I quickly determine which format was used to save the file before I open it? I don't think there is any way to tell, without opening the file, what the format is. What are the specific problems you are having? --rms www.rmschneider.com leighg wrote: > I'm having difficulty with MsProject 2007 Professional - I think it may be > because I'm switching back and forth between saving ...

Downloading files to a Silverlight Application
Hi, I have a Silverlight ASP.NET Website. The ASP.NET admin user will periodically update a xml file located the ClientBin folder. The Silverlight application downloads this file by creating and calling a xml stream reader. The concern is: I got one aspect to initially work, by placing a copy of the xml file in the Silverlight project folder with properties setting of Resource and always copy to output. When it's not a resource I get file not found in the XAP package. My question is: Are the visitor accessing the "static xml file in the silverlight project"? O...

Adding multiple files to an account (notes)
Hi, I was wondering if anyone had found a way around the problem of CRM 3.0 not allowing the uploading/attaching of multiple files to the notes field of an account record. Our CRM users need to be able to upload, say 10 jpgs of works carried out at a time, and i'm concerned they will not use the system properly if they have to repeatedly a single file ten times every time they use it. Come on CRM!!! This is basic stuff!! Has anyone found a way of doing this? Many Thanks, Martin. ...

How to enable "enable automatic update" security setting by VB cod
Hi All, I wanted to enable "enable automatic update for all workbook links" radio button through VB code (macro), As my current macro code gets link references from other excel workbook, so it is important to enable this setting by code itself. Default location of thatradio button is Excel Options-->Trust Centre-->Trust Center Settings-->External Content. ...