473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1830
tr********@hotm ail.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********@hotm ail.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********@hotm ail.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="Alexande r 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>Mittel bach</surname>
<firstname>Fran k</firstname>
</author>
<author>
<surname>Goosse ns</surname>
<firstname>Mich el</firstname>
</author>
<author>
<surname>Braams </surname>
<firstname>Joha nnes</firstname>
</author>
<author>
<surname>Carlis le</surname>
<firstname>Davi d</firstname>
</author>
<author>
<surname>Rowley </surname>
<firstname>Chri s</firstname>
</author>
</authorgroup>
<title>The <LaTeX/> Companion</title>
<titleabbrev>Co mpanion</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>Twelf th
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
6297
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 def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the...
1
2708
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 namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For...
9
1825
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 owner element. Is that right ? Like:
7
12227
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 these file attributes.
7
4538
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" MS_POSITIONING="GridLayout" class="Body" runat="server"> And in my code-behind I want to look for the leftMargin
3
1624
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 this to work on certain controls such as the ListItem in a RadioButtonList it just doesn't do anything? Does this attributes property only render for...
2
2513
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 is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in...
2
2133
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 class Book: total # is a class attribute
2
6569
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' attr2='somevalue' attrN='...'>markup</span>" 3 Dim objSpan As HTMLSpanElement = browser.Document.createElement("span") 4 objSpan.innerHTML =...
0
7457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.