using default attribute value

  • Thread starter =?ISO-8859-1?Q?L=E9na=EFc?= Huard
  • Start date
?

=?ISO-8859-1?Q?L=E9na=EFc?= Huard

-----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.

<?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>

<?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>

<?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>


<?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>

- --
(o_ Lénaïc HUARD
//\ (e-mail address removed)
V_/_ KeyID: 0x04D2E818
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBMMPBjYEjJATS6BgRAuA2AJ4t+lz0R8CeGN9XZXWUdh+qlWHpSwCgn4F7
TzhlOG7NXMguHDyDm753Tns=
=EfcB
-----END PGP SIGNATURE-----
 
?

=?ISO-8859-1?Q?L=E9na=EFc?= Huard

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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...)

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="xml"
indent="yes"
encoding="ISO-8859-1" />

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

- --
(o_ Lénaïc HUARD
//\ (e-mail address removed)
V_/_ KeyID: 0x04D2E818

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

iD8DBQFBMP4wjYEjJATS6BgRAkPuAJ9pIZEOkVIIHy+nwcq9PXYVmcxOQQCggU4k
g0eOzqck+XyTKj0EagZjqq0=
=uE4M
-----END PGP SIGNATURE-----
 
R

Richard Tobin

Lénaïc Huard said:
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
 
?

=?ISO-8859-1?Q?L=E9na=EFc?= Huard

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard Tobin a écrit:
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 :

<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>

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
//\ (e-mail address removed)
V_/_ KeyID: 0x04D2E818

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

iD8DBQFBMdSPjYEjJATS6BgRAp53AKCigWv9SsJ4rvnwoHTOgngboo2t7ACfU74x
6jwpMXbzzugXiJpU/EqmwaI=
=bfqq
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top