472,801 Members | 1,266 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

correct use of "default" attribute in XML Schema

Hi all,

what is the correct use of the "default" attribute in XML Schema?

For example:
<xs:element name="myProperty" type="xs:string" default="myDefaultValue"/>

What can I do with it? What is the meaning of <
....default="myDefaultValue" /> ?

Thank you so much.

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it

Nov 12 '05 #1
12 4857
Default means there is an application that

preempts possible words in xml.

It will expect alignment to BIG MONEY "standard" way and methods

and will not give a "notch".

For xml "USER" settings, regular xml DEVELOPERS,
and seekers of interoperability via xml -- the death sentence .

********

It stems from US neo-texan vision aka death or alive

==========

You read it here first.

==============================
==============================
Now go away and waste other people's time.
You 10 line page only has a flash object embedded
that does not work on my PC, because I have set the Kill Bit
for such crap.

"Stefano" <st****************@giasoft.it> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi all,

what is the correct use of the "default" attribute in XML Schema?

For example:
<xs:element name="myProperty" type="xs:string" default="myDefaultValue"/>

What can I do with it? What is the meaning of <
...default="myDefaultValue" /> ?

Thank you so much.

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it


Nov 12 '05 #2
What?

Excuse me, but I didn't understand what you wrote...

Thanks

Bye

"name" <user@nospam> ha scritto nel messaggio
news:ua**************@TK2MSFTNGP14.phx.gbl...
Default means there is an application that

preempts possible words in xml.

It will expect alignment to BIG MONEY "standard" way and methods

and will not give a "notch".

For xml "USER" settings, regular xml DEVELOPERS,
and seekers of interoperability via xml -- the death sentence .

********

It stems from US neo-texan vision aka death or alive

==========

You read it here first.

==============================
==============================
Now go away and waste other people's time.
You 10 line page only has a flash object embedded
that does not work on my PC, because I have set the Kill Bit
for such crap.

"Stefano" <st****************@giasoft.it> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi all,

what is the correct use of the "default" attribute in XML Schema?

For example:
<xs:element name="myProperty" type="xs:string" default="myDefaultValue"/>
What can I do with it? What is the meaning of <
...default="myDefaultValue" /> ?

Thank you so much.

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it

Nov 12 '05 #3


Stefano wrote:

what is the correct use of the "default" attribute in XML Schema?

For example:
<xs:element name="myProperty" type="xs:string" default="myDefaultValue"/>

What can I do with it? What is the meaning of <
...default="myDefaultValue" /> ?


The documentation is here:
<http://www.w3.org/TR/xmlschema-1/#cElement_Declarations>
That explains that you can put a value constraint on an element. If the
element in the XML file is empty for instance then nevertheless if a
default value is provided in the element declaration that value becomes
the "schema normalized value" in the so called "post-schema-validation
infoset".
For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value.
However I am not sure MSXML 4 or .NET do actually add such a default
value for an element, in a quick test here the value was not added.
I have also tried the Java parser and DOM with Java 1.5 and there the
default value for an element was added and appeared in the DOM.

Both MSXML 4 and .NET however add default values for attributes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Any example about the use of "default" in both elements and attributes
definition?

Thanks a lot.

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it
"Martin Honnen" <ma*******@yahoo.de> ha scritto nel messaggio
news:uF**************@tk2msftngp13.phx.gbl...


Stefano wrote:

what is the correct use of the "default" attribute in XML Schema?

For example:
<xs:element name="myProperty" type="xs:string" default="myDefaultValue"/>
What can I do with it? What is the meaning of <
...default="myDefaultValue" /> ?


The documentation is here:
<http://www.w3.org/TR/xmlschema-1/#cElement_Declarations>
That explains that you can put a value constraint on an element. If the
element in the XML file is empty for instance then nevertheless if a
default value is provided in the element declaration that value becomes
the "schema normalized value" in the so called "post-schema-validation
infoset".
For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value.
However I am not sure MSXML 4 or .NET do actually add such a default
value for an element, in a quick test here the value was not added.
I have also tried the Java parser and DOM with Java 1.5 and there the
default value for an element was added and appeared in the DOM.

Both MSXML 4 and .NET however add default values for attributes.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #5


Stefano wrote:
Any example about the use of "default" in both elements and attributes
definition?


You yourself have given an example with a default value for an element
in your original post.

As for an attribute e.g.
<xs:element name="element-name">
<xs:complexType>
<xs:sequence>
<!-- define some element content here -->
</xs:sequence>
<xs:attribute name="attribute-name" type="xs:string"
default="Kibology" />
</xs:complexType>
</xs:element>

For an example focussed introduction to W3C XML schema have a look at
<http://www.w3.org/TR/xmlschema-0/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #6
I mean... an example using a DOM: MSXML or .NET.

You said:
"For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value."

Can you show me an example about it?

Thanks!

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it
"Martin Honnen" <ma*******@yahoo.de> ha scritto nel messaggio
news:uv**************@tk2msftngp13.phx.gbl...


Stefano wrote:
Any example about the use of "default" in both elements and attributes
definition?


You yourself have given an example with a default value for an element
in your original post.

As for an attribute e.g.
<xs:element name="element-name">
<xs:complexType>
<xs:sequence>
<!-- define some element content here -->
</xs:sequence>
<xs:attribute name="attribute-name" type="xs:string"
default="Kibology" />
</xs:complexType>
</xs:element>

For an example focussed introduction to W3C XML schema have a look at
<http://www.w3.org/TR/xmlschema-0/>

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #7


Stefano wrote:
an example using a DOM: MSXML or .NET.

You said:
"For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value."


I also said that it doesn't work for me with elements for MSXML 4 or
..NET, it is not clear whether that could be regarded a bug or not.
Oleg or anyone else reading, what do you think, should the default value
defined for an element in an XML schema result in the default value
showing up in the DOM with MSXML 4 or .NET?

But it works with attributes, for example if the schema document is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="GOD">
<xs:complexType>
<xs:attribute name="name" default="Kibo" type="xs:string" />
</xs:complexType>
</xs:element>

</xs:schema>

and the XML document is

<?xml version="1.0" encoding="UTF-8"?>
<GOD />

then the following JScript program using MSXML 4 shows that with
validation against the schema turned on the attribute with the default
value is added:

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument.async = false;

var xmlURL = 'test2005032202.xml';
var schemaURL = 'test2005032202Xsd.xml';

var wellFormed = xmlDocument.load(xmlURL);

if (wellFormed) {
// no validation, yields null for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
xmlSchemaCache.add('', schemaURL);

xmlDocument.schemas = xmlSchemaCache;

var valid = xmlDocument.load(xmlURL);

if (valid) {
// with validation yields Kibo for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}
A similar C# .NET program would be:

const string xmlURL = @"test2005032202.xml";
const string schemaURL = @"test2005032202Xsd.xml";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(xmlURL);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

XmlValidatingReader xmlValidator = new XmlValidatingReader(new
XmlTextReader(xmlURL));
xmlValidator.Schemas.Add(null, schemaURL);

xmlDocument.Load(xmlValidator);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

Output then is

name: .
name: Kibo.

so there the validation ensures that the attribute with the default
value is added.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #8
It's great!

Thank you so much.

Another question...

I tried to add another alert, after the loading of XSD.
alert('document: \n' + xmlDocument.documentElement.xml);

This alert displays:
<GOD />
not
<GOD name="Kibo" />
as I expected.

It's like "xmlDocument.documentElement.xml" property isn't affected by the
applying of the schema.
Only "xmlDocument.documentElement.getAttribute('nam e')" works, retreiving
the default value.

Can you say me why this happen?

My goal is to retrieve a string containing the xml representation with
default values for attributes.

Thank you so much!
--
Stefano Giannone
MCP .NET
http://www.giasoft.it
"Martin Honnen" <ma*******@yahoo.de> ha scritto nel messaggio
news:%2******************@TK2MSFTNGP15.phx.gbl...


Stefano wrote:
an example using a DOM: MSXML or .NET.

You said:
"For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value."


I also said that it doesn't work for me with elements for MSXML 4 or
.NET, it is not clear whether that could be regarded a bug or not.
Oleg or anyone else reading, what do you think, should the default value
defined for an element in an XML schema result in the default value
showing up in the DOM with MSXML 4 or .NET?

But it works with attributes, for example if the schema document is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="GOD">
<xs:complexType>
<xs:attribute name="name" default="Kibo" type="xs:string" />
</xs:complexType>
</xs:element>

</xs:schema>

and the XML document is

<?xml version="1.0" encoding="UTF-8"?>
<GOD />

then the following JScript program using MSXML 4 shows that with
validation against the schema turned on the attribute with the default
value is added:

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument.async = false;

var xmlURL = 'test2005032202.xml';
var schemaURL = 'test2005032202Xsd.xml';

var wellFormed = xmlDocument.load(xmlURL);

if (wellFormed) {
// no validation, yields null for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
xmlSchemaCache.add('', schemaURL);

xmlDocument.schemas = xmlSchemaCache;

var valid = xmlDocument.load(xmlURL);

if (valid) {
// with validation yields Kibo for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}
A similar C# .NET program would be:

const string xmlURL = @"test2005032202.xml";
const string schemaURL = @"test2005032202Xsd.xml";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(xmlURL);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

XmlValidatingReader xmlValidator = new XmlValidatingReader(new
XmlTextReader(xmlURL));
xmlValidator.Schemas.Add(null, schemaURL);

xmlDocument.Load(xmlValidator);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

Output then is

name: .
name: Kibo.

so there the validation ensures that the attribute with the default
value is added.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #9
Another question...

I see that only MSXML 3.0 is shipped with IE 6... right?

So, the client needs to install MSXML 4 to run the javascript you suggested
me.

Can you suggest me a version of that javascript that uses MSXML 3.0 ?
(I simple tried to change 4 to 3 in the new ActiveXObject, but it doesn't
work)

Thank you so much!

Bye
--
Stefano Giannone
MCP .NET
http://www.giasoft.it
"Martin Honnen" <ma*******@yahoo.de> ha scritto nel messaggio
news:%2******************@TK2MSFTNGP15.phx.gbl...


Stefano wrote:
an example using a DOM: MSXML or .NET.

You said:
"For instance if you build a DOM then the DOM of such an element could
contain the default value even if the XML input markup doesn't contain
that value."


I also said that it doesn't work for me with elements for MSXML 4 or
.NET, it is not clear whether that could be regarded a bug or not.
Oleg or anyone else reading, what do you think, should the default value
defined for an element in an XML schema result in the default value
showing up in the DOM with MSXML 4 or .NET?

But it works with attributes, for example if the schema document is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="GOD">
<xs:complexType>
<xs:attribute name="name" default="Kibo" type="xs:string" />
</xs:complexType>
</xs:element>

</xs:schema>

and the XML document is

<?xml version="1.0" encoding="UTF-8"?>
<GOD />

then the following JScript program using MSXML 4 shows that with
validation against the schema turned on the attribute with the default
value is added:

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument.async = false;

var xmlURL = 'test2005032202.xml';
var schemaURL = 'test2005032202Xsd.xml';

var wellFormed = xmlDocument.load(xmlURL);

if (wellFormed) {
// no validation, yields null for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}

var xmlSchemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.4.0');
xmlSchemaCache.add('', schemaURL);

xmlDocument.schemas = xmlSchemaCache;

var valid = xmlDocument.load(xmlURL);

if (valid) {
// with validation yields Kibo for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
}
A similar C# .NET program would be:

const string xmlURL = @"test2005032202.xml";
const string schemaURL = @"test2005032202Xsd.xml";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(xmlURL);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

XmlValidatingReader xmlValidator = new XmlValidatingReader(new
XmlTextReader(xmlURL));
xmlValidator.Schemas.Add(null, schemaURL);

xmlDocument.Load(xmlValidator);

Console.WriteLine("name: {0}.",
xmlDocument.DocumentElement.GetAttribute("name"));

Output then is

name: .
name: Kibo.

so there the validation ensures that the attribute with the default
value is added.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #10


Stefano wrote:

I tried to add another alert, after the loading of XSD.
alert('document: \n' + xmlDocument.documentElement.xml);

This alert displays:
<GOD />
not
<GOD name="Kibo" />
as I expected.

It's like "xmlDocument.documentElement.xml" property isn't affected by the
applying of the schema.


It seems the serializer for the xml property in MSXML doesn't serialize
default attributes, the documentation at
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmproxml.asp>
does not tell whether or not default attributes should be serialized.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #11

Stefano wrote:
I see that only MSXML 3.0 is shipped with IE 6... right?
That is correct.
So, the client needs to install MSXML 4 to run the javascript you suggested
me.
If you want to have an MSXML version that supports W3C XML schemas then
you need to have at least MSXML 4, MSXML 3 only supports DTDs (and so
called XDR schemas) but not W3C XML schemas.
Can you suggest me a version of that javascript that uses MSXML 3.0 ?


A DTD allows you to define default values for attributes too, here is an
example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE GOD [
<!ELEMENT GOD EMPTY>
<!ATTLIST GOD
name CDATA "Kibo">
]>
<GOD />

Then parsed with MSXML 3 the program

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.3.0');
xmlDocument.async = false;

var xmlURL = 'test2005032301.xml';

var valid = xmlDocument.load(xmlURL);

if (valid) {
// with validation yields Kibo for attribute value
alert('name: ' + xmlDocument.documentElement.getAttribute('name'));
alert(xmlDocument.xml);
}
else {
alert(xmlDocument.parseError.reason);
}

again shows the attribute value 'Kibo' taken from the DTD but also shows
that in this case too the default attribute is not serialized.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #12
Great answer!

Thank you so much!

--
Stefano Giannone
http://www.giasoft.it
Nov 12 '05 #13

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

Similar topics

8
by: whtevr | last post by:
Consider this HTML on an ASP page called default.asp in a virtual directory: <FORM name="Flogin" id="Flogin" action="" method=post> </FORM> Do I HAVE to put the literal "default.asp" into the...
4
by: Mark Erikson | last post by:
I'm currently writing an HTML editor for the PocketPC, and one of my Tag class's properties is DefaultAttributes. The idea behind this is that some tags are almost always used with certain...
18
by: Clark Nu | last post by:
It seems that when I define a fuction,I can set a default value to some of the peremeters.When I call the fuction without some of them,the fuction will use the default value automaticlly then...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
0
by: kapcreations | last post by:
Also posted this on the ADSI board using system.directoryservices, how can I poll AD for a specified user and determine which server their exchange mail folder is on? I assume this is somewhere...
15
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press "ENTER" key. But in the VB.net I can't find this...
7
by: natG | last post by:
Using the IBM Universal JDBC (Type 4) driver; Can one specify a default schema as part of the url? Some application servers do not allow sending a default sql command upon connection, so I can't...
7
by: George Sakkis | last post by:
A situation that often comes up is having to initialize several instance attributes that accept a default value. For a single class, passing the default values in __init__ is fine: class...
2
by: aj | last post by:
SQL Server 2005 64-bit 9.00.3042 SP2 When I map a database user to a login, I can specify a default schema for that user. After that, any SQL from that user w/o an explicit schema will be...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.