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

Similar Articles

[PageSpeed] 27

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 (1778)
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 up new outlook mail account
i can not set up a new account on my outlook, i keep saying establish network connection with a correct sign but searching for my mail account shows X can you please advise Are you trying to setup a POP3 mail account or an Exchange account? Also, what version of Outlook are you using? "rashid" <rashid@discussions.microsoft.com> wrote in message news:C59D04C0-C1C9-4BD1-AE00-2009D25B221D@microsoft.com... > i can not set up a new account on my outlook, i keep saying establish > network > connection with a correct sign but searching for my mail account shows X > ...

How do I set up an argument which asks for multiple criteria
I am trying to use an argument that asks for one of three criteria (2345P, 8319T, or 7026J) in cell C108, and if it finds it, enters the amount of yet another cell, G108 into cell K108, and if not enters 0 into cell K108. It seems there are too many arguments for the "if" argument, and I can't seem to get the "lookup" argument to work either. Is there another argument I should be working with? Thanks -- Diver Try: =IF(OR(C108="8319T",C108="2345P",C108="7026J"),G108,0) "bj" wrote: > try in K108 > =if(or(c108=&qu...

OWA Set Rule problem
I have successfully install the Exchange 2003 with SP1 in the Windows Server 2003. Anything alright exclude the rules function in OWA. I try to set the rules from any then "move to" or "copy to" specify folder are no problem, but "forward to" other email address, its don't work. I try to input the email address in the contact and then select from the contact, but the result also don't work. The rules can save and I can receive the incoming email in the Exchange 2003/Outlook or OWA, but it don't forward to my specify email address. I try to...

How do I set the 'Set Synchronizing Client' field
We have a number of outlook clients using CRM that have the 'Set Synchronizing Client' select box greyed out. We need to tick them so that they are able to synchronize tasks etc. Can any one help me find out why these are greyed out and then set them so that they can synchronize thanks In my experience, that checkbox is always greyed out for the first install that is performed for a user. The only time that checkbox becomes active is if a second copy of CRM is installed for a user who already has CRM installed on another PC.... Normally the box is checked and grey. If that is...

Can't Restore a Password Protected File
I have never used a Passport but the Money File is password protected. I've never been able to restore a backup because it wants to use my Passport but the Passport is NOT associated with the Money File (so when I do try to use the Passport, it tells me it isn't associated...duh). I've been using Money 2003 and have now upgraded to 2005 but can't get to any of my info from the backup. I have lots of backups but can't restore ANY of them in 2003 or 2005. Help please... In microsoft.public.money, Andy wrote: > have never used a Passport but the Money File is pa...

How to set backcolour
Hello All I have a continuous form containing a number field (long integer) called [v_colour]. This field contains the number of a certain colour - as per the numbers that are used in the format properties for back colour etc. I would like to set the back colour for the form's [v_colour] text box to be the value of the field: e.g. If the value of [v_colour] in the first record is 255, I want the back colour of the textbox for that record to be bright red. I tried this as the OnLoad event for the form: [v_colour].backcolour = [v_colour].value .... but this resulted in the back colour of...

Applying Percent Decrease Across Set Periods
I have a column which includes dates when items were purchased. I have used the DATEDIF function to find the number of years between that date and today's date. I now want to decrease the purchase amount 10% for every year calculated via the DATEDIF function. Any ideas, is this possible, why can't I think...? -- Hunt&amp;Peck ------------------------------------------------------------------------ Hunt&amp;Peck's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=32961 View this thread: http://www.excelforum.com/showthread.php?threadid=527873 ...

Set Regional Settings but not Language
Hi I have a multi-language APP en-US, es-ES, it-IT I usually change Languages and Locales by using the CultureInfo to switch Languages System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo("es-ES"); My issue is - what if the user wants to View App in english and use the Regional Options on a PC in say Spain ??? If I change the CultureInfo to en-US then they can view APP in English ( English satelite assemblies) but date and numbers will be in US format If I change the CultureInfo to es-ES then date and numbers will be in Spain forma...

Reading Pane Settings
I did a search for an answer to this question and have not found one. If I missed an answer already posted, please direct me to the right place. I have Outlook 2007 and set up the "right" reading pane for my e-mail. Now when I go to my calendar it is set up the same way - calendar on the left (same size as the inbox) and then there is a blank space to the right that is the size of the reading pane/preview. To the right is the to-do bar (which I have no problem with). I don't know why there is a reading/preview pane on the calendar when there is nothing to preview, and I...

Work Hours setting excludes specified hours from Scheduling
I am miffed by this problem. I specify a work hour schedule for a user. When I schedule a CRM User as a Resource for a Service in Scheduling of a Service Activity with Requested Time of ASAP and click Find Available Times, the values for Avilable Times returned are outside of the Work Hours I specified for the user and not within the work hours. When I drill into the Work Hours for this User, the Calendar view shows Cross Day rather than 8:00AM - 5:00PM I speciied for work hours and editing the hours reveal the correct hours in the Work Hours. What gives? Never mind. Figured out w...

Attach file but send dir image
I attach a file to my email. I send the email and also three other messages with attached images of my directory lists. How do I stop sending these images? Why are they being sent? Outlook 2000 I am running Norton AntiVirus to filter both the incoming and the outgoing mail. The problem occurs in the filtering of the outgoing mail. NAV support suggests that the problem is a corrupted Symantec Redirector and directed me to their document# 200205160084213 - How to update the Symantec Redirector files. >-----Original Message----- >I attach a file to my email. >I send the email and al...

Unsave file
Dear All, I have updated Excel file, but i was wrong to press the Button File Save to "NO". Please advice either there is any temporary file Excel in the computer...in order for me to save what i have done in updating the file... Your help is highly appreciated.. Andri Sorry, no. To save future tears, you may want to look at: file|saveas|tools|general options and check always create backup If you save, you'll get a backup copy built with a name like: backup of book1.xlk ===== And one tip that may help (also in the future)... If you know that you don't want to change ...

cannot delete or rename file on desktop
i have a file on my desktop named con.stock030801.xls. i cannot rename or delete this file. the message that pops up says that the file should be renamed but it wont let me. any suggestions? The problem is that "con." (con - dot - anything) is a Windows reserved name ("con" is short for "console" (the screen) and is used with command prompt commands). I don't know how it was created but generally it's not possible. For instance I cannot rename a file to your file's name, nor save a new one with that name in Excel. So this is not an Excel probl...

Is it possible to format a PSObject with a .ps1xml file?
This might be a totally ridiculous question...but here goes anyway: I have a couple of filters in modules that write PSObjects to output using code like: $x = New-Object PSObject -Property @{ one = "one" two = "two" } Write-Output $x There's just way more properties. How does one specify 'default' formatting styles for a System.Management.Automation.PSCustomObject like you can with other types using .ps1xml files? That may not even be the right question to ask. What I'd like would be a way to define the default formatting for ...

how to convert dat files?
I don't know how to convert .dat files into excel. Is it as simple as downloading an upgrade? How do I find out what file conversions are supported by excel? Hi you may explain from which program these dat files orginate -- Regards Frank Kabel Frankfurt, Germany "HungerArtist" <HungerArtist@discussions.microsoft.com> schrieb im Newsbeitrag news:C61EF460-CE8E-46D6-A793-BB9F0B6EF8BC@microsoft.com... > I don't know how to convert .dat files into excel. Is it as simple as > downloading an upgrade? > > How do I find out what file conversions are supported by...

Outlook "Arrange By" option does not retain its setting
In outlook 2007, I use a custom view for my inbox, and I have the Group By option checked to"Automatically group according to arrangement." This has been workn flawlessly until today, when I realized Outlook did not like a particular mouse click; perhaps I clicked on the border of two options or some other anomoly that caused the window toflash once. The end result was that my Arrange By option changed to "From" when I had previously set it to "Conversation." Now, whenever I hange it backto "Conversation," leave the inbox and come back, ...

Excel File
When we received a excel file through mail , while opening the file i received a error :corrupt file, run repair to to extract the contents. The same file when opened on another PC received an error : read only. Please asuggest a immediate solution Can you right-click the file, go to properties and uncheck read only? -- Sincerely, Michael Colvin "ritu" wrote: > When we received a excel file through mail , while opening the file i > received a error :corrupt file, run repair to to extract the contents. > > The same file when opened on another PC received an error ...

Path\File name length problem Excel Crash on save as
I have a problem saving a file in code using: thisworkbook.SaveAs The problem is if the file and path length is greater than 150 then the Excel app crashes. I have tried this over a network as well as a local drive. Has anyone ever seen this problem? Thanks in advance, Stewart Rogers ...

Digital File Attacments to Transactions
Another question... I see that Quicken 2006 has resurrected a feature they included in one of their earlier versions; the ability to attach digital images to transactions (paycheck stubs, receipts,...whatever). This was a *terrific* feature and really loved it. It saved me a *lot* of trouble, particularly when I had to produce a receipt for an item that I had purchased a long time ago, yet was still under warranty. I could go on about how useful this feature was to me, but I digress... I was a loyal user of Quicken and TurboTax almost since the beginning, that is until the TurboTax ...

Sharing Outlook data files across a home network
I have two computers hooked up to a network - a desktop hardwired to my router/modem and a laptop connected wirelessly to the router/modem. I run Outlook on the desktop to download and access all my emails and contacts, but i'd also like to be able to access all this data on my laptop. Basically, i want to synchonise my email and contacts on both machines in real time. Is there any way to do this? I have never found a way to do this with stand-alone Microsoft products over the last 6 years (unless you install an Exchange Server!). There are a few aftermarket solutions like ...

interactive buttons, multiple sets
hi folks I'm sure one of you good folks will save my bacon as usual I have a series of websites, all of which exhibit the same odd behavior with interactive buttons. I have a bunch of buttons in the left margin, each of which pulls up ( lets call it ) a chapter, and in each 'chapter' are a number of related pages. On the top of each page is an imbedded page which has 'page numbers' for all the 'pages' in that chapter. So, it's a grid where the 'vertical' buttons in the left margin and the 'horizontal' buttons at the top comb...

Creation of .PST Files
Hi, I have a 3 GB mailbox that I need to copy in one or more .PST Files First of all, I need to know if there is an Exmerge version that create a more-than-2GB file (Like Outlook 2003) and If not, If there are an application that create and split automatically into 2GB file thanks in advance last i heard, exmerge is still limited to 2gb. usually i set a date range in order to get items pulled out of mailbox and into 2 or more pst files. "Javier Villegas" <jvillegas@elsitio.net> wrote in message news:O05byWLTEHA.3608@TK2MSFTNGP11.phx.gbl... > Hi, > > I have a 3 ...

How do I set OOR
I have searched the help menu and have had no luck finding out how to set my outlook 200 to send an OOR (Out of Office Reply) Any assistance would be great If you are in an Exchange environment (ask your administrator if you do notknow) you can set the Out of the Office Assistant which is located under Tools. If you are not in an Exchange environment you can create a rule that replies on all e-mails. The downside of this is that you'll have to have your Outlook open all the time for the rules to process. Make sure you set some exceptions (for instance based on the subject field so ...

Set Focus
I have text box that I input data into and I was wondering if it is possible to set focus to the text box and avoid clicking on the box. I thought the term is Set Focus, but can't find any information or example that would help in doing so. Any help would be appreciated .. PPT 2003. Look at the following page for code to set focus on a text box: http://officeone.mvps.org/vba/activate_shape.html - Chirag PowerShow - View multiple PowerPoint slide shows simultaneously http://officeone.mvps.org/powershow/powershow.html "Phil K" <PhilK@discussions.microsof...

Where is the Outlook .pst file located?
Using Windows XP, Outlook 2002 Two Questions: Can someone tell me where the main .pst file for Outlook is located in Windows, so I can back it up onto a remote server? If there are several folders containing emails, dodes each folder have to be backed up separately, or can all emails be backed up by backing up one .pst file? Thanks, "The Hun" <ed@LAocean.com> wrote in message news:5222a132-f978-4065-a5f0-7c7c5c9e33eb@e1g2000pra.googlegroups.com... > Using Windows XP, Outlook 2002 > > Two Questions: > > Can someone tell me where the main .pst file for Outloo...