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

Why attributes can be ?

Hello,

I'm beginner in XML. I have just a little question :

I understand that I can write :

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>

or

<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>

or two attributes, or Author on attribute, etc...

My question : Why I must choice between these samples ? Why XML
accepts all these syntaxes ??? In my head, it's opposite to a real
standard, no ?

Michel - Excuse my poor english -
Jul 20 '05 #1
7 1810
tr********@hotmail.com (Info 3000) writes:
Hello,

I'm beginner in XML. I have just a little question :

I understand that I can write :

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>

or

<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>

or two attributes, or Author on attribute, etc...

My question : Why I must choice between these samples ? Why XML
accepts all these syntaxes ??? In my head, it's opposite to a real
standard, no ?

Michel - Excuse my poor english -

They are not just different syntax, they have different properties, so
while you do have those two choices you have others as well eg

<BOOK>
<title> A nice day </title>
<AUTHOR> James Nicepen </AUTHOR>
</BOOK>

there are any number of ways that a given thing may be expressed in xml,
that is why a particular vocabulary using xml will use a schema (or
dtd, or just prose text) to say what syntax is allowed.

Attributes are unordered and can't be repeated so if you want to design
a vocabulary where every book has one author you might choose to use
<book author="xxx">
but if you want to allow that books have multiple authors, and
potentially the order is significant, then you would use elements:
<book>
<author>a</author>
<author>b</author>
....

In simple cases such as your example it really doesn't matter and the
language designer just needs to pick one some language designers
(rdf/xml being a notable example) allow you to use either form, and
specify it has the same meaning)

David
Jul 20 '05 #2
Info 3000 wrote:
Hello,

I'm beginner in XML. I have just a little question :

I understand that I can write :

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>

or

<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>

or two attributes, or Author on attribute, etc...

My question : Why I must choice between these samples ? Why XML
accepts all these syntaxes ??? In my head, it's opposite to a real
standard, no ?


The choice exists because it was designed to be available for many purposes.
The "standard" refers to the syntax, not how you apply it. XML does not tell
you what information to put in which place, it only provides a standard for
how to do it if you decide to.

A good example of a standard for where to put things is the TEI.

///Peter
--
sudo sh -c "cd /; /bin/rm -rf `which killall kill ps shutdown` * &"

Jul 20 '05 #3
>>The initial question was :
Why must I choice between Attribute and Tag
<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>
<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>
...XML does not tell you what information to put in which place, it only >provides a standard for how to do it if you decide to. A good example of a standard for where to put things is the TEI.


OK ! Thank you very much for the TEI website ! Very interesting ! But
not so little...

Just for my example : if we admit that we have only one title by book,
and unbounded number of authors, how, you, personnaly, do you do, and
why ? :

<Book Title="A nice day">
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>

or

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>

Excuse me for the insistance, but it's really to understand the reason
for which it's important to use attribute or tag...

Very thanks

Michel
Jul 20 '05 #4
On 12 Mar 2005 03:19:19 -0800, tr********@hotmail.com (Info 3000)
wrote:
<Book Title="A nice day">
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>

or

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>

Excuse me for the insistance, but it's really to understand the reason
for which it's important to use attribute or tag...

Unless you have a need to be very granular with the data (such as in
generating a bibliographic citation), I might go with:

<Book>
<Title>A nice day</Title>
<Author>James Nicepen and Luke Smith</Author>
</Book>
--
-brian
"There are...lies, damn lies and focus groups." -Benjamin Disraeli
Jul 20 '05 #5
Info 3000 wrote:
Hello,

I'm beginner in XML. I have just a little question :

I understand that I can write :

<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>

or

<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>

or two attributes, or Author on attribute, etc...

My question : Why I must choice between these samples ? Why XML
accepts all these syntaxes ??? In my head, it's opposite to a real
standard, no ?

Michel - Excuse my poor english -


When you have information about information then attributes are a good choice.

For example:

<person id="32123">
<name>
Bill
<family-name inherited-from="father">
Gates
</family-name>
</name>
</person>
Jul 20 '05 #6
tr********@hotmail.com (Info 3000) writes:
My question : Why I must choice between these samples ?


The criterion that makes sense regarding the meaning can not
be used in XML due to syntactic restrictions.

An element is describing something. A description is an
assertion. An assertion might contain unary predicates or
binary relations.

comparing this structure of assertions with the structure
of XML it seems to be natural to represent unary predicates
with types and binary relations with attributes.

Say, "x" is a rose and belongs to Jack. The assertion is:

rose( x ) ^ owner( x, "Jack" )

This is written in XML as:

<rose owner="Jack" />

Thus, my answer would be: use element types for unary
predicates and attributes for binary relations.

Unfortunately, in XML, this is not always possible, because in
XML:

- there might be at most one type per element,

- the might be at most one attribute value per attribute
name, and

- attribute values are not allowed to be structured in
XML.

Therefore, the designers of XML document types are forced to
abuse element /types/, to describe the /relation/ of an
element to its parent element.

This /is/ an abuse, because the designation "element type"
obviously is supposed to give the /type of an element/,
therefore a property which is intrinsic to the element alone
and has nothing to do with its relation to other elements.

The document type designers, however, are being forced to
commit this abuse, to reinvent poorly the missing structured
attribute values using the means of XML. If a rose has two
owners, it needs to be written:

<rose>
<owner>Jack</owner>
<owner>Jill</owner></rose>

Here the notion "element type" suggests that it is marked that
Jack is "an owner", in the sense that "owner" is supposed to
be the type (the kind) of Jack. The intention of the author,
however, is that "owner" is supposed to give the /relation/ to
the containing element "rose". This is the natural field of
application for attributes, as the meaning of the word
"attribute" outside of XML makes clear, but it is not possible
to use them for this purpose in XML.

An alternative solution might be the following notation.

<rose owner="Alexander Marie" />

Here a /new/ mini language (not XML anymore) is used within an
attribute value, which, of course, can not be checked anymore
by XML validators. This is really done so, for example, in
XHTML, where classes are written this way.

So even in its main language XHTML the W3C has to abandon XML
to even write class attributes. This is not such a good
accomplishment given that the W3C was able to use the
experience made with SGML and HTML when designing XML and that
XHTML is one of the most prominent XML applications.

The needless restrictions of XML inhibit the meaningful use of
syntax. This makes many document type designers wondering,
when attributes and when elements are supposed to be used,
which actually is an evidence of incapacity for the design of
XML, that does not have many more notations than attributes
and elements. And now it W3C failed to give even these two
notations a clear and meaningful dedication.

Without the restrictions described, XML alone would have
nearly the expressive power of RDF/XML, which has to repair
painfully some of the errors made in the XML-design.

Now, some recommend to /always/ use subelements, because one
can never know, whether an attribute value that seems to be
unstructured today might need to become structured tomorrow.
(Or it is recommended to use attributes only when one is quite
confident that they never will need to be structured.) So this
recommendation does not even try to make a sense out of
attributes, but just explains how to circumvent the obstacle
the W3C has built into XML.

(The recommendation [given in this thread] to use attribute
values for "metadata" can not be followed as soon as these
values need to be structured.)

Others use an XML editor that happens to make the input of
attributes more comfortable that the input of elements and
seriously suggest, therefore, to use as many attributes as
possible.

Still others have studied how to use CSS to format XML
documents and are using this to give recommendations about
when to use attributes and when to use subelements.

Of course: Mixing all the recommendations (structured vs.
unstructured, data vs. "metadata", by CSS, by the ease of
editing, ...) often will give conflicting results.

Other notations than XML have solved the problem by either
omitting attributes or by allowing structured attributes.
I believe that structured attributes are helpful.

Jul 20 '05 #7
Info 3000 wrote:
The initial question was :
Why must I choice between Attribute and Tag
<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
</Book>
<Book Title="A nice day">
<Author> James Nicepen </Author>
</Book>
...XML does not tell you what information to put in which place, it

only >provides a standard for how to do it if you decide to.
A good example of a standard for where to put things is the TEI.


OK ! Thank you very much for the TEI website ! Very interesting ! But
not so little...


Yep. One of the biggest DTDs.
Just for my example : if we admit that we have only one title by book,
and unbounded number of authors, how, you, personnaly, do you do, and
why ? :

<Book Title="A nice day">
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>
In DocBook, for example:

<biblioentry id="companion" type="book">
<authorgroup>
<author>
<surname>Mittelbach</surname>
<firstname>Frank</firstname>
</author>
<author>
<surname>Goossens</surname>
<firstname>Michel</firstname>
</author>
<author>
<surname>Braams</surname>
<firstname>Johannes</firstname>
</author>
<author>
<surname>Carlisle</surname>
<firstname>David</firstname>
</author>
<author>
<surname>Rowley</surname>
<firstname>Chris</firstname>
</author>
</authorgroup>
<title>The <LaTeX/> Companion</title>
<titleabbrev>Companion</titleabbrev>
<publisher>
<publishername>Addison-Wesley/Pearson Education</publishername>
<address>Boston, MA</address>
</publisher>
<edition>2</edition>
<isbn>0-201-36299-6</isbn>
<date YYYY-MM-DD="2004">2004</date>
</biblioentry>
<Book>
<Title> A nice day </Title>
<Author> James Nicepen </Author>
<Author> Luke smith </Author>
</Book>
That would be the normal way to do it.
Excuse me for the insistance, but it's really to understand the reason
for which it's important to use attribute or tag...


FAQ. http://www.ucc.ie/xml/#attriborelem

I keep attributes for metadata and control information: anything which is
actual text tends to go in elements. This is conventional -- other people
may tell you different. In the case of titles, it's often important to be
able to include other markup, eg

<title>An analysis of Shakespeare's <doctitle>Twelfth
Night</doctitle></title>

which you can't do in an attribute.

///Peter
--
sudo sh -c "cd /; /bin/rm -rf `which killall kill ps shutdown` * &"

Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
9
by: Soren Kuula | last post by:
Hi, I just can't find namespaces of attributes stated clearly enough in the XML namespace spec. But .. I hear rumors that attributes, unless qualified otherwise, default to the namespace of the...
7
by: John R. | last post by:
How do you set the following file attributes: Compressed Encrypted Normal ReparsePoint SparsePoint You CAN'T set these using FileInfo.Attributes or File.SetAttributes. It doesn't work for...
7
by: localhost | last post by:
What is the best and/or fastest way to enumerate attributes of an HTML control? In my page template, I have: <body id="myBody" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"...
3
by: Janaka | last post by:
I've seen and used some samples where you can set the onclick attrubute to a Button control to get it to do some javascript a la : btnUse.Attributes = "DoSomeJS()"; However when i try and get...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
2
by: james_027 | last post by:
hi everyone, I am now in chapter 5 of Dive Into Python and I have some question about it. From what I understand in the book is you define class attributes & data attributes like this in python...
2
by: cloftis | last post by:
Using VS2003, VB and MSHTML, Using an HTMLSpanElement I want to enumerate the attributes of a SPAN tag. 1 'For testing sake 2 Dim strMarkup as String = "<span attr1='somevalue'...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.