using default attribute value

Discussion in 'XML' started by =?ISO-8859-1?Q?L=E9na=EFc?= Huard, Aug 28, 2004.

  1. -----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
    //\
    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, Aug 28, 2004
    #1
    1. Advertising

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

    http://www.atmedia.net/KlausRusch/
     
    Klaus Johannes Rusch, Aug 28, 2004
    #2
    1. Advertising

  3. -----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:eek:utput 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
    //\
    V_/_ KeyID: 0x04D2E818

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

    iD8DBQFBMP4wjYEjJATS6BgRAkPuAJ9pIZEOkVIIHy+nwcq9PXYVmcxOQQCggU4k
    g0eOzqck+XyTKj0EagZjqq0=
    =uE4M
    -----END PGP SIGNATURE-----
     
    =?ISO-8859-1?Q?L=E9na=EFc?= Huard, Aug 28, 2004
    #3
  4. In article <4130c44a$0$21110$>,
    Lénaïc Huard <> 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
     
    Richard Tobin, Aug 28, 2004
    #4
  5. Re: using default attribute value (Xerces and libxml2 schema validator discrepanties)

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

    Richard Tobin a écrit:

    > In article <4130c44a$0$21110$>,
    > Lénaïc Huard <> 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
    //\
    V_/_ KeyID: 0x04D2E818

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

    iD8DBQFBMdSPjYEjJATS6BgRAp53AKCigWv9SsJ4rvnwoHTOgngboo2t7ACfU74x
    6jwpMXbzzugXiJpU/EqmwaI=
    =bfqq
    -----END PGP SIGNATURE-----
     
    =?ISO-8859-1?Q?L=E9na=EFc?= Huard, Aug 29, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,098
    Henry S. Thompson
    Mar 6, 2006
  2. C Gillespie
    Replies:
    3
    Views:
    441
    Peter Hansen
    Mar 22, 2005
  3. Replies:
    1
    Views:
    4,422
    Joe Kesselman
    Aug 2, 2006
  4. Replies:
    8
    Views:
    540
  5. dkmd_nielsen
    Replies:
    6
    Views:
    259
    Joel VanderWerf
    Nov 26, 2008
Loading...

Share This Page