473,386 Members | 2,129 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,386 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 4911
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.