Why attributes can be ?

Discussion in 'XML' started by Info 3000, Mar 11, 2005.

  1. Info 3000

    Info 3000 Guest

    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 -
    Info 3000, Mar 11, 2005
    #1
    1. Advertising

  2. (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
    David Carlisle, Mar 11, 2005
    #2
    1. Advertising

  3. Info 3000

    Peter Flynn Guest

    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` * &"
    Peter Flynn, Mar 11, 2005
    #3
  4. Info 3000

    Info 3000 Guest

    >>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
    Info 3000, Mar 12, 2005
    #4
  5. Info 3000

    Brian Guest

    On 12 Mar 2005 03:19:19 -0800, (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
    Brian, Mar 12, 2005
    #5
  6. 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>
    Tjerk Wolterink, Mar 12, 2005
    #6
  7. Info 3000

    Stefan Ram Guest

    (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.
    Stefan Ram, Mar 13, 2005
    #7
  8. Info 3000

    Peter Flynn Guest

    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` * &"
    Peter Flynn, Mar 13, 2005
    #8
    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. Max
    Replies:
    1
    Views:
    468
    Joe Kesselman
    Sep 22, 2006
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    855
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,744
    Smokey Grindel
    Dec 2, 2006
  4. P4trykx
    Replies:
    2
    Views:
    1,786
    bruce barker
    Jan 31, 2007
  5. james_027

    class attributes & data attributes

    james_027, Jun 20, 2007, in forum: Python
    Replies:
    2
    Views:
    358
    Bruno Desthuilliers
    Jun 20, 2007
Loading...

Share This Page