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

Similar Articles

[PageSpeed] 29

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:

IM will not set the User defined field in the Item Migration
I am using the Inventory Item Destination adapter to bring in new items to GP. The problem IM does not offer a way to set Item Categories, So I decide to use the "User Defined 2" field in the migration to import the item category information. This is not working. Its not updating this field. And I took a look at the physical inventory table, and did not see any reference to my entries. Anyone know why it's not working or a better approach to entering the Item Categories? -- Thanks for your help Did You define the Item category values in the system? If Yes, You can use...

How do you create an "html" file? #2
How do you create an "html" file? We need this file to display messages & promotions on the costumer display monitor ...

If then Else is not workint to set a field as bold
Hi, I put the following comand in forms load property to set some bolds and is not working: If Me.CodigoRubrica = "TOTAL" Then Me.SumOfMes1.FontBold = True End If This form as a datasheet view, view. Can you help?? regards, Marco Use a number from 0-8 to designate the Font Weight like: [SumOfMes1].FontBold = 6 God Bless, Mark A. Sam "Marco" <Marco@discussions.microsoft.com> wrote in message news:3C381A89-BCD8-429A-ABCC-B7C1D15E481C@microsoft.com... > Hi, > > I put the following comand in forms load property to set some bolds and > is >...

Setting up a Custom type, User-defined, Default Chart
When I try to save the User-defined Chart, I get an error saying "can not save this workbook because another open workbook with the same name or add-in. Choose a different name, or close the other workbook or add-in before saving." I don't have an add-in interfering with this, as far as I know. I save the workbook under another name and the User-defined Chart is not saved. How can I save a User-defined Chart and how can I make it my default? I am using MS Excel 2000 (9.0.3821 SR1). ...

Cannot copy item w. "Flag complete" set
If a message has "Flag Complete" set (the checkmark), then I cannot copy the message. I can copy it with any other flag set (all the color flags), and removing the "Flag Complete" also enables me to copy the message... I can move it, delete it, etc. but I cannot copy a message to a different folder if it has the "Flag Complete" set. Error message: "Can't copy the items. Cannot complete the copy operation. The items may have been moved or deleted, or you may not have sufficient permission." Our environment: Outlook 2003 (11.5608.5606) Exchange 2003...

I can't open Office Data File from CDs #2
Dear technical experts, I have been facing a security problem with Microsoft Outlook files. I exported Outlook items into Office outlook files (with the extension is .pst). The exported files were firstly saved on my computer (different path and location in comparison with default path of Office Outlook files in Documents and Settings). I can open my exported files easily. Because the size of outlook items is very large, I would like to save Office outlook files on another storage device in stead of using hard drives of my computer. I made copy these files to a flash drive (USB dri...

Schemaset : schema compiled form code shows no PSVI elements
I accidentally put this on another group - this is the more likley home... The first code fragment creates the simplest of XML Schemas is code. After the “Compile()” method is called on the schemaset objetc, the schema element count is zero – but I was expecting one element in the PSVI. I saved the XML output in the console window to a file, and ran the second code fragment below to load in the XML from the file, and compile the schema. The element count of the schema is now 1 – as expected. Why does the compile for a schema created in code not set to schema element count to 1? I also...

How do I set up a 11 X 17 spreadsheet?
How do I set up a spreadsheet for a 11 x 17 printout? You should be able to select 11x17 as a paper size option in the Page Setup dialog. If you do not have an option for 11x17 you will need to set up (and select) a printer that supports 11x17" output. HTH, TK >-----Original Message----- >How do I set up a spreadsheet for a 11 x 17 printout? > >. > ...

Inserting PDFs into Publisher File
I can't insert PDF's into my publisher newsletter by trying the insert command. I have to copy it and then past and it loses some quality. Anyone know how to get around this insertion problem? Thanks Greg Save the .pdf as another format and then insert it. -- JoAnn Paules MVP Microsoft [Publisher] "gporell@southshoresenior.com" <anonymous@discussions.microsoft.com> wrote in message news:11af01c50a30$d6c8d0c0$a401280a@phx.gbl... >I can't insert PDF's into my publisher newsletter by > trying the insert command. I have to copy it and then > pas...

Publisher 2003- message
I have used Publisher for a 120+ page "news letter" for the past 5 years. Upgraded to 2003 early last year. Have had a problem with fonts changing indescriminately (no sollution as yet). Latest problem - having spent many hours on a new document which includes grafics and text - I received the message - Publisher cannot open the file. HELP PLEASE Surely after 5 years you have a backup or two. It is never a good idea to use the same document over and over without re-saving it with a new name. Maybe you have a copy in a temporary folder Type %temp% in the address bar of Wind...

Converting mysql query result to xml
Hi all, I'm a newbie in .net xml programming, so please be patient. And sorry for my uncorrect english, too. I'm going to explain my problem: I've built a web service which responds to ferries timetable requests. It receives an xml document with this format: <TimeTableRequest> <Routes> <Route> <Company></Company> <DeparturePort>ptf</DeparturePort> <ArrivalPort>pio</ArrivalPort> <Date>2006-12-20T13:00:00</Date> </Route> <Route> <Company></Company> ...

save array to file, read it back in
Hi, I just have an RGB volume buffer allocated like: unsigned char pBuffer = new unsigned char[256 * 256 * 50 * 3]; and I'd like to dump it straight to a file so I can read it back in exactly as above. Can I do something like this: ofstream o("C:\\test.raw"); o << pBuffer; o.close(); // Later on read it back in... ifstream i("C:\\test.raw"); unsigned char *pLater = new unsigned char[256 * 256 * 50 * 3]; i.read(); i.close(); Thanks I would write it out in ASCI and then convert when reading back. Since you are using MFC...

Excel crashes with linked files
Hi All, I was recently issued a new laptop and now Excel crashes frequently, sometimes upon opening a file, sometimes upon closing a file, and most recently upon changing the font. The most obvious thing that all the files have in common is that they contain links to other worksheets. Does anyone have any idea what may be causing this and/or how to fix it? I'd appreciate any suggestions. Erin Erin, have you tried un-installing Excel/Office and re-installing? It sounds like something is wrong with Excel. Bob Flanagan Macro Systems http://www.add-ins.com Productivity add-ins an...

Is there any way to Create a self-extracted file programmatically ?
Hi,guys!I need to create a self-extracted cabinet file with my app,but i don't know how to achieve this.I found ms cabinet sdk,but it dosen't mention the self-extracted cabinet.And i know IEpress can create a self-extracted cabinet file,but i want to write my app as IExpress. Is there any way i can achieve this ? Thank you advance! There is a cabarc.exe for creating cabinet file along with platform sdk. There is also a cabinet sdk available here:- http://download.microsoft.com/download/platformsdk/cab/2.0/w98nt42kmexp/en-us/Cabsdk.exe -- Vipin Aravind Microsoft MVP "how...

Excluding full path to linked file on a networked drive
Hello, I have two excel files -- A and B. Both files are saved on a network drive in the same directory. In file A, I have links to cells in file B. Because the files are in the same directory, is it possible to not have Excel show the entire path to file B in the formulas in file A that link to file B? The network path is quite long and it makes it difficult to read the formulas? If file B is open, the formulas just show the name of the file,i.e. [B]. Is it possible to always have this shown? THanks, How about using a cell reference that contains the file path? -- Jim Cone Portlan...

on the excel's startup i want to set a cell value to zero
on the excel's startup i want to set a cell value to zero. Sub initialization() Range("Input_Output_Sheet!D9").Value = 0 End Sub is there a way to run this macro at the excels startup automatically Michael, Presuming you mean when a certain workbook is opened, not when Excel starts up, you want to initialize that cell, put this in the ThisWorkbook module of the workbook: Private Sub Workbook_Open() Range("Input_Output_Sheet!D9").Value = 0 End Sub If you really want to do this to a certain workbook when Excel is started up, I think you'll have to pu...

Report Timeout Settings
We have a beast of a report that actually check the system for duplicates and based on the criteria selected within a parameter, it can take up to 6 minutes to run. From Visual Studio, the report generates after 6 minutes, but from within CRM, it seems that once the report generation hits the 5 minute mark, it errors out and we get the following error in the report viewer… Error An error has occurred Does anyone know of a way to increase the report processing timeout setting within CRM? Optimizing the report any further is not an option and the duplicate checking method can be comp...

Merging Two Files
Hi, I am getting ready to marry up two schedules (around 6000 task lines) and am trying to find a potentially quicker solution than what I have planned (just in case plan A doesn't go so well for me). Two months ago I took a copy of my master file and began to add much needed work into it, however it was not yet authorized work, so I had to continue providing status into the main master file up to this point in time. Now that the work will be authorized in May, I need to take the current master file, and make sure all of the "what-if" modifications from the se...

Shared File & Freeze panes issue
We are using a Shared file, but the Freeze panes at times "resets" so that it appears the screen is frozed unitl you reset freeze panes. This is not due to user changesm but occurs in the original file that was emailed. Is ther any way to prevent this? There's a guy at work who sometimes applies Window|Freeze panes to a filtered list. While the list is filtered the way he has it, you can see the titles and the data nicely. But when you do Data|filter|show all (or reset the filter), the cell used to set the freeze panes is now off the viewable screen and it looks like t...

Corrupted files
My laptop computer recently had a mother board that fried and had to get a new one. Before taking the computer in for repair, I had all of my documents backed up on DVDs. When I reinstalled Office 2007, I receive error messages on some documents saying that the file is corrupted. Is there any way to recover the data on this corrupted file? I have tried to open the files by using plain text but all I get is scrambled letters and numbers and signs. Try opening them with WordPad or Open Office. But to see how badly corrupt they are (presuming they are docx format), rename them with...

Unable to read File #4
I have one particular file in Excel 97 which I open and update daily (stock market stuff) and each day I copy the days entries and paste it below for the next day. Been doing this for years with no hitch until a couple of months ago then one day I tried to open the file and got a notice "Unable to Read File". Tried everything I knew (which is not much) with no luck. Fortunately I had the file saved to a flash drive and was able to open it there and "Save As" back to by hard drive. It worked fine for a while, then last week it happened again, but I didn't bother to ret...

Convert file/backup Money 2000 on Money 2004
I have Money 2000 and I have buy Money 2004; but I can't convert my old file or backup created with Money 2000 on Money 2004. Why? We need some more information. What error messages do you see? What happens that you don't expect? What doesn't happen? -- Regards Bob Peel, Microsoft MVP - Money Hints/Tips http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny UK Wishes/Suggestions mnyukwsh@microsoft.com "Stefano" <sborghi@deda.com> wrote in message news:02ca01c39f92$f68d8fe0$a001280a@phx.gbl... > I have Money 2000 and I have buy Money 2004...

My 2 Outlook 2003 profiles download both sets of messages
I am running Outlook 2003 on MS XP. Have used one profile for years with no probem. Just added a new profile for my business email and I'm set up to ask for which profile to use each time. No matter which profile I use, incoming message from both email accounts are downloaded into the current persona folder's inbox. My business messages and home messages are now pretty mixed up. Have double and triple checked my settings in each profile and don't see any errors. When I run the "test settings" that part works fine. Have contacted my ISP but they find...

OL2003 "file as"
I've imported an address list from excel. Before that I changed the standard for "file as" to "company (last,first)" But after importing the contacts are filed as "last, first" without company. Does someone know what do to?!?!? Thanxxx KH The setting only apply to newly created Contacts, not Contacts you import. To change those, you'd have to use code. -- Russ Valentine [MVP-Outlook] "KH Koell" <anonymous@discussions.microsoft.com> wrote in message news:07ca01c39f04$54808420$a001280a@phx.gbl... > I've imported an address lis...

set number of rows equal in mutiple columns
I am having trouble setting the number of rows equal across my spreadsheet. For example i have about 2000 records in column b and there should be that many rows in column d...however there are zero's goin all the way down my sheet (to file 65536). What i want to do is write something in vb so set number of rows in column b and make that many rows in all the other columns. It has to be variable because across my 3 spreadsheet pages the number of files varies depeding on the amount of information that i import. I have been working on this for a few days and it seems to me it should be a sim...