Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 2nd, 2006, 04:45 AM
Randy Williams
Guest
 
Posts: n/a
Default 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
  #2  
Old August 2nd, 2006, 05:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Retrieving default values specified from XML Schema file



Randy Williams wrote:

Quote:
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/
  #3  
Old August 2nd, 2006, 08:15 PM
Randy Williams
Guest
 
Posts: n/a
Default Re: Retrieving default values specified from XML Schema file

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:
Quote:
>
>
Randy Williams wrote:
>
>
Quote:
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/
>
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles