By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

using default attribute value

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I've some namespace problems when defining default values for attributes.

My problem seems to come from the fact that the attributes are defined in a
different namespace from the element.

I've defined the XLink attributes in xlink.xsd. (I've copied just a subset)
I've written a personal schema defining elements in an other namespace in
schema.xsd. I defined default values for some XLink attributes.
But, when I process doc.xml,
the element

<link xl:href="http://www.google.fr">Google</link>

becomes

<link xl:href="http://www.google.fr" show="new" actuate="onRequest"
type="simple">Google</link>

But I expected:

<link xl:href="http://www.google.fr" xl:show="new" xl:actuate="onRequest"
xl:type="simple">Google</link>

I don't understand why the XML processor (Xerces in my case) deletes the xl
namespace prefix.
Note, that the processed file is not valid any more !!!
As a consequence, Mozilla doesn't interpret this link node as an hypertext
node. :-(

How can I do in order to define default values for attributes that are
defined in a different namespace from the elements ??

Thanks for any help !
LÚna´c.
doc.xml <<<
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="copy.xsl" ?>
<root xmlns="http://MySchema"
xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://MySchema schema.xsd">
<link xl:href="http://www.google.fr">Google</link>
<link xl:href="http://www.w3.org">W3C</link>
<link xl:type="simple" xl:href="http://www.xmlfr.org" xl:show="new"
xl:actuate="onRequest">XML</link>
</root>
end of doc.xml <<< processed doc.xml <<<
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="copy.xsl" ?>

<root xmlns="http://MySchema" xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://MySchema schema.xsd">
<link xl:href="http://www.google.fr" show="new" actuate="onRequest"
type="simple">Google</link>
<link xl:href="http://www.w3.org" show="new" actuate="onRequest"
type="simple">W3C</link>
<link xl:type="simple" xl:href="http://www.xmlfr.org" xl:show="new"
xl:actuate="onRequest">XML</link>
</root>
end of processed doc.xml <<< xlink.xsd <<<
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">

<xs:schema xmlns="http://www.w3.org/1999/xlink"
xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/1999/xlink"
elementFormDefault="qualified"
attributeFormDefault="qualified">

<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="simple" />
<xs:enumeration value="extended" />
<xs:enumeration value="locator" />
<xs:enumeration value="arc" />
<xs:enumeration value="resource" />
<xs:enumeration value="title" />
<xs:enumeration value="none" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>

<xs:attribute name="href" type="xs:anyURI" />

<xs:attribute name="show">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="new" />
<xs:enumeration value="replace" />
<xs:enumeration value="embed" />
<xs:enumeration value="other" />
<xs:enumeration value="none" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>

<xs:attribute name="actuate">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="onLoad" />
<xs:enumeration value="onRequest" />
<xs:enumeration value="other" />
<xs:enumeration value="none" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>

<xs:attribute name="label" type="xs:NCName" />

<xs:attribute name="from" type="xs:NCName" />

<xs:attribute name="to" type="xs:NCName" />
<xs:attributeGroup name="simpleLink">
<xs:attribute ref="xl:type" fixed="simple" />
<xs:attribute ref="xl:href" use="optional" />
<xs:attribute ref="xl:show" use="optional" />
<xs:attribute ref="xl:actuate" use="optional" />
</xs:attributeGroup>

</xs:schema>
end of xlink.xsd <<< schema.xsd <<<
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">

<xs:schema xmlns="http://MySchema"
xmlns:my="http://MySchema"
xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://MySchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/1999/xlink"
schemaLocation="xlink.xsd" />

<xs:element name="root" type="my:rootType" />

<xs:complexType name="rootType">
<xs:sequence>
<xs:element name="link" type="my:linkDefaultType"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="linkBaseType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="xl:simpleLink" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="linkDefaultType">
<xs:simpleContent>
<xs:restriction base="my:linkBaseType">
<xs:attribute ref="xl:show" default="new" />
<xs:attribute ref="xl:actuate" default="onRequest" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>

</xs:schema>
end of schema.xsd <<<

- --
(o_ LÚna´c HUARD
//\ Le**********@laposte.net
V_/_ KeyID: 0x04D2E818
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBMMPBjYEjJATS6BgRAuA2AJ4t+lz0R8CeGN9XZXWUdh +qlWHpSwCgn4F7
TzhlOG7NXMguHDyDm753Tns=
=EfcB
-----END PGP SIGNATURE-----
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
LÚna´c Huard wrote:
But, when I process doc.xml,
the element

<link xl:href="http://www.google.fr">Google</link>

becomes

<link xl:href="http://www.google.fr" show="new" actuate="onRequest"
type="simple">Google</link>


Your document references an XSL stylesheet copy.xsl. How do you process
the document?

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Klaus Johannes Rusch wrote:
LÚna´c Huard wrote:
But, when I process doc.xml,
the element

<link xl:href="http://www.google.fr">Google</link>

becomes

<link xl:href="http://www.google.fr" show="new" actuate="onRequest"
type="simple">Google</link>


Your document references an XSL stylesheet copy.xsl. How do you process
the document?


In fact, I needed a stylesheet in order to see it with Mozilla (without
stylesheet, Mozilla displays the tree). And in order to see how the default
attributes are imported by an Xml processor, I used Xalan.

That's the reasons why I use a stylesheet which does nothing. (Or should
does nothing but copying the source tree without any modification...)
copy.xsl <<<
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"
indent="yes"
encoding="ISO-8859-1" />

<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>

</xsl:stylesheet>
end of copy.xsl <<<

- --
(o_ LÚna´c HUARD
//\ Le**********@laposte.net
V_/_ KeyID: 0x04D2E818

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBMP4wjYEjJATS6BgRAkPuAJ9pIZEOkVIIHy+nwcq9PX YVmcxOQQCggU4k
g0eOzqck+XyTKj0EagZjqq0=
=uE4M
-----END PGP SIGNATURE-----
Jul 20 '05 #3

P: n/a
In article <41***********************@news.free.fr>,
LÚna´c Huard <le**********@laposte.net> wrote:
I don't understand why the XML processor (Xerces in my case) deletes the xl
namespace prefix.


I think it must be a bug in the Xerces schema validator, or whatever
you are using the serialize the schema-validated document.

-- Richard
Jul 20 '05 #4

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard Tobin a Úcrit:
In article <41***********************@news.free.fr>,
LÚna´c Huard <le**********@laposte.net> wrote:
I don't understand why the XML processor (Xerces in my case) deletes the
xl namespace prefix.


I think it must be a bug in the Xerces schema validator, or whatever
you are using the serialize the schema-validated document.


Well ! Let's try another XML parser ! ;-)

I tried xmllint ; but it seems to compil the Schema not as I expected :

The lines

<link xl:href="http://www.google.fr">Google</link>
<link xl:href="http://www.w3.org">W3C</link>
<link xl:type="simple" xl:href="http://www.xmlfr.org" xl:show="new"
xl:actuate="onRequest">XML</link>

produces the following errors:

doc.xml:10: element link: Schemas validity error : Character or element
children are not allowed, because the content type is empty.

These errors don't appear with Xerces (through Xalan)

As a reminder : here is how the link element is defined :
schema.xsd extract <<<
<xs:element name="link" type="my:linkDefaultType" />

<xs:complexType name="linkBaseType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="xl:simpleLink" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="linkDefaultType">
<xs:simpleContent>
<xs:restriction base="my:linkBaseType">
<xs:attribute ref="xl:show" default="new" />
<xs:attribute ref="xl:actuate" default="onRequest" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
end of schema.xsd extract <<<


The linkBaseType is not designed to be used (I should put abstract="true").
But I need it to define default values for some attributes.
If I put the <xs:attribute ref="xl:show" default="new" /> element inside the
linkBaseType definition, the XML parser complains that xl:show attribute is
defined twice in the type. That's the reason why I used a derivation.

In the derivation, I don't remind that the content of the element is a
xs:string. Xerces considers that the content is unchanged whereas xmllint
considers that the content of the derived type is empty.

Which is right and how to enforce the fact that the content of the derived
type is still an xs:string ?

LÚna´c.
- --
(o_ LÚna´c HUARD
//\ Le**********@laposte.net
V_/_ KeyID: 0x04D2E818

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBMdSPjYEjJATS6BgRAp53AKCigWv9SsJ4rvnwoHTOgn gboo2t7ACfU74x
6jwpMXbzzugXiJpU/EqmwaI=
=bfqq
-----END PGP SIGNATURE-----
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.