Retrieving default values specified from XML Schema file

Hi All,

I have an VS.NET 2003 app which will be processing XML files, some of which 
will have empty elements (for example, <Item />).  I have an XSD file which 
should supply default values, but I am not able to read these plugged in 
value using an XMLDocument object.  The validation is working fine--it's just 
not providing any default values.

Has anybody tried this?  Am I must be missing something?  This is one of 
those that "should be simple..."

Here's a simplifed version of the code and XML files:

XmlDocument xmldoc = new XmlDocument();
XmlSchemaCollection myXmlSchema = new XmlSchemaCollection();
myXmlSchema.Add("", new XmlTextReader("test.xsd"));
XmlValidatingReader myReader = new XmlValidatingReader(new 
XmlTextReader("test.xml"));
myReader.Schemas.Add(myXmlSchema);
xmldoc.Load(myReader);
Console.WriteLine (xmldoc.SelectSingleNode ("/Data/Item").InnerText);

I would expect this to output 'abc', which is defined in the XSD (see below).

XMLDoc:
<?xml version="1.0"?>
<Data>
	<Item />
</Data>

XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Data">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Item" type="xs:string" default="abc"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Many thanks in advance for any assistance.

Randy Williams
hawaiianmetal@hotmail.com
0
Williams (30)
8/2/2006 3:51:02 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
647 Views

Similar Articles

[PageSpeed] 38


Randy Williams wrote:


> I have an VS.NET 2003 app which will be processing XML files, some of which 
> will have empty elements (for example, <Item />).  I have an XSD file which 
> should supply default values, but I am not able to read these plugged in 
> value using an XMLDocument object.  The validation is working fine--it's just 
> not providing any default values.

I find default values in the DOM with .NET 2.0 but not with .NET 1.x. 
Can you change to .NET 2.0?


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
8/2/2006 5:02:46 PM
Hi Martin,

Thanks for the quick reply.  We're set with 1.1 for now.  There's an upgrade 
plan in progress, but it probably won't roll through until early '07.

Randy

"Martin Honnen" wrote:

> 
> 
> Randy Williams wrote:
> 
> 
> > I have an VS.NET 2003 app which will be processing XML files, some of which 
> > will have empty elements (for example, <Item />).  I have an XSD file which 
> > should supply default values, but I am not able to read these plugged in 
> > value using an XMLDocument object.  The validation is working fine--it's just 
> > not providing any default values.
> 
> I find default values in the DOM with .NET 2.0 but not with .NET 1.x. 
> Can you change to .NET 2.0?
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
8/2/2006 7:16:00 PM
Reply:

Similar Artilces:

If I accidently replace a saved file can I retrieve the old file?
No. PLEASE write your question in the body of the post and NOT just the subject. Have a look here: http://dts-l.org/goodpost.htm -- Gordon Burgess-Parker Interim Systems and Management Accounting www.gbpcomputing.co.uk "kamabiv" <kamabiv@discussions.microsoft.com> wrote in message news:2A547F5D-AA2C-44D7-AEC7-8961A81AC4E5@microsoft.com... > ...

Best Practises setup with AD or File Server
Hi, We have a scenario where we are retiring out dedicated backup server. Currently we are using Symantec Backup Exec 11d. However, instead of replacing the dedicated server, their is a suggestion that I use existing servers for Backup Exec Are their known issues installing backup exec on a DC which also holds FSMO roles (PDC etc)? The other option is to install backup exec (and tape drive) on a file server which hosts the H and S drives. what do you think? I would use the file server. Presumably it is being accessed during the day when no backups are running. The b...

2000 File Export Issue
Running Outlook 2000 (9.0.0.2711) and trying to export a date range to Excel. I'm following the instructions, but all I get are the column headings -- no data. What am I doing wrong? ...

File Share Witness
Please help me understand something - I think I get the concept of using a file share witness in CCR, however, I have read that it is suggested that this server also be a Hub Transport Server. How can this be if a Hub Server is not cluster aware? Isn't the file share witness server configured to be part of the cluster? On Jan 31, 12:25 pm, PM <P...@discussions.microsoft.com> wrote: > Please help me understand something - I think I get the concept of using a > file share witness in CCR, however, I have read that it is suggested that > this server also be a Hub Transpor...

retrieving mail from another location on other computer. HELP
When i travel i don't always go with my own laptop. Can i access my outlook mail on the web ? If your mail provider makes it available on the web, yes. "Juliemrm" <Juliemrm@discussions.microsoft.com> wrote in message news:D0191906-4B63-4020-AAC4-58041BD51703@microsoft.com... : When i travel i don't always go with my own laptop. Can i access my outlook : mail on the web ? Yes & No You wont be able to access the mail you have downloaded / sent within Outlook, unless its an imap account Otherwise see Tom's post "Juliemrm" <J...

Problem with VBA and assignment of a value
I have a form w/subform and need to display the average of one field (AverageAge) and the count of records in the subform on the form somewhere else than in the subform. I calculate AverageAge as Average([Age] in the form footer. I get the record count using the recordCount property o the subform. The problem is that I can't sem to get the value 'AverageAge' into an unbound textbox. Me.AvgAge = Me.Team_Members_subform.Form.AverageAge produces the error Application-Defined or Object-Defined error. Me.AvgAge = Me.Team_Members_subform.Form.Age gives me the correct age f...

HIGH CPU in WMP 11 playing VC-1 (1080) WMV files
I know it's going to take some CPU to process it, but the picture is stuttering and jerky, CPU abot 65% in WMP 11 XP SP3. If I render and play the same file in Graph Edit, it plays beautifully and CPU is down to the 30% mark. I have an Nvidia 8600GT with recent drivers. I know that DVXA could be a factor, I'm not sure if it's being used or not - How to tell ? Why is WMP is doing such a poor job ? Any info appreciated. On Sat, 1 May 2010 14:32:33 -0700, "Dave and Rosanna" <davexnett05@yahoo.com> wrote: >I know it's going to take some C...

Linking 2 files
Hi I got a file A with numbers and a file B with links to the first. If I insert new rows between 2 lines, the links in the other file don't change after i press recalculate. Is this normal? Who can help me? THX, L Excel isn't a database. keep your DATA in a DATABASE and spit on people that use Excel Luc Vandenhoeck wrote: > Hi > > I got a file A with numbers and a file B with links to the first. > If I insert new rows between 2 lines, the links in the other file don't > change after i press recalculate. Is this normal? > Who can help me? > THX, L ...

Exch 2007 ntfs file permissions
Is there a document available showing all the major areas of Exchange 2007 file structures correct NTFS permissions ? ...

Excel doesn't open the file
When I click on an excel file (or even a word doc), excel opens to a gray page. I then have to search for and open the file from the file list. The file associations are set correctly. This has just started recently. It used to open directly to the file I clicked on. Any ideas on how to fix this? Thanks in advance. Steve First, check to make sure the workbook isn't actually open: Window|Arrange|Tiled If it's not visible, then sometimes one of these works: Tools|Options|General|Ignore other applications (uncheck it) --- or --- Close Excel and Windows Start Button|Run excel /u...

How do I open a publisher file from a different version?
I do not have Norton AV on my computer. How can I open this file?? Hi Joan (Joan@discussions.microsoft.com), in the newsgroups you posted: || I do not have Norton AV on my computer. How can I open this file?? What version of Publisher do you have? What version of Publisher is the file? -- Brian Kvalheim Microsoft Publisher MVP http://www.publishermvps.com ~pay it forward~ This posting is provided "AS IS" with no warranties, and confers no rights. ...

Best way to read in a large hierarchial XML file
First, please forgive my newness to XML. I've used it to serialize/ deserialize objects, exporting and importing datasets, and other such things that pretty much automate reading in the file. I've done extensive googling, and most examples people give are so simplistic it makes me want to cry. Most are one level deep and utilize XMLDocument or other in-memory processes, or do things like: while(reader.Read()) { //do things I'm not going to show you how to do } Needless to say, I'm frustrated. I wish I could use XMLDocument, but theoretically my input file can range from a...

converting Postal codes to numeric value
i need to convert 80,000 postal codes to a 9 digit numeric value. where M5R3T8 converts to 135183208 and M4P3J9 converts to 134163109 each letter of the alphabet needs to reflect the numbers 1 - 26. a = 01 b = 02 c= 03 d= 04 e = 05 f = 06 g = 07 h = 08 i = 09 j = 10 etc I am currently copying the postal codes to a separate sheet and doing a find and replace. sounds crude, i know but it is the only way i know. Hope you can help! thanks! -- InNeedoflHelp Are the alphabet characters always upper case? Do you know how to run/use VBA code? "InNeedoflHelp" <InNeedoflHe...

How do I make Microsoft outlook my default e-mail handler?
I have windows xp home edition, and office 2000. I have the option to make outlook express my default e-mail but not outlook and that is what I need to use for the calendar and news capabilities. Carol S. cwacarol@cox-internet.com Control Panel > Internet Options > Programs -- Russ Valentine [MVP-Outlook] "cwacarol" <cwacarol@discussions.microsoft.com> wrote in message news:4D70BC32-206E-4298-9C71-DD5103DFB4A5@microsoft.com... >I have windows xp home edition, and office 2000. I have the option to make > outlook express my default e-mail but not outlook and t...

Outlook is retrieving data
Hello, We get this message "Outlook is retrieving data from Microsoft Exchange Server 'Exch. server name' ...." every so often on Outlook 2002 (XP) and with Exchange 2000 server. The O/S is varied between Windows 98 SE and Windows XP Pro both running Office XP Prof. This slows down the performance quite a bit and on some cases it freezes up Outlook and the user can't do anything. Any ideas ? Thanks. JS ...

Data Validation lists
I want to have an incell drop down list - but I also want to enter an item not on the list. Most of the time the drop down list is fine - once in a while I want to enter an item not on the list. Is there a way to set up data validation to be able to do this? This would be a list of text choices - the list does not consist of values. Thanks Richard -- rgarber50 ------------------------------------------------------------------------ rgarber50's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=11350 View this thread: http://www.excelforum.com/showthread.php?thr...

Importing data from a file into an Excel file
I would like any information on importing data from a Label making program into an Excel file. At work we use a from in Excel and I would like to import my info from my labels to this form. The export command on my label making program says I need to export to an ASCII text file. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ Sue, Once you have obtained you ASCII text file: from the menu (in excel) pick: File -> Open then change the Files of type: to Text Files ...

Large number of transaction log files #2
I've got around 160 E00*.log files kicking around in the mdbdata directory of an Exchange Server 2003 server. I can't seem to find any references about the number of log files. Is there something I should be doing to reduce the number of log files or is the server ok? Cheers! Colin Never mind, I figured it out. The backup process was failing because of a security password reset and thus not consolidating the log files. :) Cheers, Colin "Colin Bowern" <colinbowern@nospam.indimensions.com> wrote in message news:OduryEI8EHA.3124@TK2MSFTNGP11.phx.gbl... > I&#...

Periodically listing files in a folder
Hi I have a folder containing photos which are updated on a daily basi (added to,replaced and removed.) I'm trying to set up a trackin system to monitor the folder contents. Can anyone point me in the right direction to listing the contents of folder using VBA? Ideally I'd like to have the code associted with a button which update the file listing completely within excel. I currently generate a txt file from a dos prompt, link to this an update whenever neccesary. Cheers To -- haven10 ----------------------------------------------------------------------- haven104's Pr...

how to import value from a cell into another cell behind a text st
Hi, I try to put a value from one cell into another cell behind a text string, i.e., getting the 20 in B1 in to A1 behind a word such as Result to get Result (20) in A1. Is there a formaula to do this? Thanks, Xianbo ="Result " & B1 Thanks, Dave. Works great! "Dave O" wrote: > ="Result " & B1 > > If the text you are wanting to combine is in a list or another cell you can use the concatenate formula to combine both into one cell. "Xianbo" wrote: > Hi, > > I try to put a value from one cell into another cell behind...

OL blocking large .exe file
I have received a large attachment in my inbox from a friend (14MB) which I want to open, but OL has blocked it. Is there any way of accessing it? Yes, you can override the default security assuming your Outlook security is not managed/locked-down by your Exchange server. Here is the article with details on how to override default block on Level 1 Attachments (CAUTION: we block .exe's for a very good reason, please use this setting with discretion) : 318515 OL2000: Cannot Access Attachments http://support.microsoft.com/?id=318515 290497 OL2002: You Cannot Open Attachments http://su...

excel don't erase temp ($...) files
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Excel dont erase the temps files when I close (besides the quit its ok) I have to delete them manually, because if not the file keeps &quot;only reading&quot;. I had tried repair permission, but doesnt work, the only solutions its changing the files to another new folder, but only works for one or two days. No, it 'don't' :-) As I understand it, apps do not write or delete files in OS X. That is a service reserved by the OS & provided to the apps on demand, so if the temp files aren't ...

Default Save Folders
If I open an attachment and forget to "save as" to a specific folder - my system defaults to a directory that I cannot even see. How do I get access to this folder? C:\Documents and Settings\my profile\local settings\temporary internet ... \random # My IT guy can configure the default folder through the registry but cannot figure out how to display the folder when I don't "save as" Thank you, -- Miguel82 Its a hidden temp file, in which the files may no longer exist, and in any case are not stored in an identifiable name. You can use third party tools which st...

Importation of Backup file
Hello, I'm sorry but I can't speack english very well. I'm looking for any solution about my Microsoft Money. Some weeks ago I had a problem with my pc. I've saved all my data but I had to reinstall all my programs. My Microsoft Money 2000 too. Now I've installed the same Money program but if I try to open my backup file, I have to type my old password, but the file don't works because it says that the password is incorrect. And I'm sure that the password is correct. Please help me because I can't open my old data. Thanks in advance for your kind help. Th...

Sumif and zero values question
I have a long list of product codes. Against each code is a number obtained from a sumif calculation from another long list of the same codes. A large number of these sumif results are zero. Is there a way of automatically hiding the zero lines such that if one became greater than zero it would automatically appear in the list? In other words I would like to be able to automatically only list those product codes where the sumif result was greater than zero. (Hope that's clear!) Thanks "Gordon" <GordonBP1@yahoo.invalid> wrote in message news:elseLfUeEHA.596@TK2MSFTNGP1...