473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
ha***********@hotmail.com
Aug 2 '06 #1
2 1541


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/
Aug 2 '06 #2
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/
Aug 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: inquirydog | last post by:
Hi- I am using xml to hold configuration data for a project, and using schema to define what the configuration file should look like. I wanted to get some advice on an intelligant way to...
10
by: Dan | last post by:
I use the settings grid to create a setting named "ServerName". Now i want to retrieve it in code and i can't figure out how. This should be incredibly obvious but i cant get it. I have tried...
7
by: Larry Bud | last post by:
I have a simple data object that returns two columns in a dataset, ID and DESC, for example. When I bind a dropdownlist to this <dataobjectmethod>, I have to manually enter the column names for...
0
by: digiexist | last post by:
Is it possible to specify an XML schema that define a number of optional XML elements each with their own default value such when an XML instance document (that uses this XML schema file and does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.