473,387 Members | 1,904 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,387 software developers and data experts.

using default attribute value

-----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
4 2905
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
-----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
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
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
3
by: Michael Ahlers | last post by:
Obviously if you're looping or using a template, choosing output based on the current iteration is easy. For example, if you're walking a set of elements and you want index % 2 == 0 produce one...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Asha | last post by:
greetings, i need to upload an .xls file using a secure connection. so i though of using https... can i know how this can be done?
44
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
2
by: Nicolas | last post by:
Hi everybody... In Xerces 2.7.0 it is explicitly stated that, no matter how one removes an attribute (attList->removeNamedItem, attList->removeNamedItemNS, domElement->removeAttributeNode,...
0
ADezii
by: ADezii | last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was...
7
by: Anz | last post by:
I used the javascript functions as shown below. <a href="javascript:;;;" onclick="this.style.behavior='url(#default#homepage)'; this.setHomePage(location.href);"> But this code works for IE,...
2
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.