What is the difference between "node", "attribute", "element" and "tag" in XML?

Asked

Viewed 4,637 times

9

I am confused about some features and terms of the XML markup language that are: knot, attribute, element and tag, I would like to know what each of them is and what are the differences between them?

Follow this XML to help with the explanation and I served as an example:

<alunos>
    <aluno>
        <nome>Dener</nome>
        <nota1>7</nota1>
        <nota2>8</nota2>
        <nota3>5</nota3>
        <nota4>10</nota4>
    </aluno>

    <aluno>
        <nome>Raphael</nome>
        <nota1>8</nota1>
        <nota2>6</nota2>
        <nota3>6</nota3>
        <nota4>9</nota4>
    </aluno>

    <aluno>
        <nome>Ana</nome>
        <nota1>5</nota1>
        <nota2>6</nota2>
        <nota3>4</nota3>
        <nota4>5</nota4>
    </aluno>
</alunos>
  • question easily answered by google, right from the start, I found this material, see if it serves you: http://www.dicas-l.com.br/arquivo/tutorial_xml-schema.php#. V6-kVLOVveQ

  • 3

    @Armandomarquesnephew the idea of the site and bring the explanations here to be available to the community, I read about it in google and msm so remain confused on the subject.

  • opa, therefore, so ok, Gentlemen moderators, it is up to you to my signage, on my part, with the comment of the author, I consider pertinent the subject because it really needs further clarification

  • 4

    @Armandomarquessobrinho it is not necessary to signal for something that you yourself can do, this starting on the site, is normal. You can leave the comment, it will serve as a source for who will answer. PS: the questions and answers on the site will not only be for those who ask, but for future users.

2 answers

11


Knot or Node is all minimal part of XML. Sets of nodes form other nodes. Comparing, roughly, with programming language, are tokens. Some nodes have specific meaning and some of them are described below.

Element or element is a complete block of data and marking that gives semantics to the data. It includes some of the nodes described below.

Tag or label is the marking of what a given means. It is always determined by a word within the sign <>. There may be a tag that opens the block and one that closes. Some are auto closers.

Some tags may have some specific information that gives better semantics to the data that are contained in them, are called attribute (attribute). Usually it is a key pair (indicating what you are talking about there) and value (what informs the attribute), but there are those that are only key.

There is still text within certain tags which is the data. From the XML point of view it is always a text. If the data is of some other type that deserves a conversion, it will be determined by tag and its attributes, or schema configure this and an application that knows how to interpret it better (very common).

So

<nota1>7</nota1>

There is a datum 7 which, of course, is a knot. There’s a couple of tags encapsulating this knot giving the semantics that this is the nota 1. All of this together forms another node. This specific node is an element.

There are no attributes at all in the XML presented in the question. But it could be, I don’t know, something like this:

<nota1 prova=true>7</nota1>

prova=true is an attribute.

All this together is another knot:

<aluno>
    <nome>Dener</nome>
    <nota1>7</nota1>
    <nota2>8</nota2>
    <nota3>5</nota3>
    <nota4>10</nota4>
</aluno>

All the XML presented in the question is another node.

It is common for people to have difficulty defining whether something should be an element or just an attribute of the element. It is necessary to understand what is a given (which is the fundamental part of an element) and what is only a "decoration" of the given (the attribute). This attribute is the same as HTML, after all XML is very similar. In a way we can say that HTML is a specialized XML, and specified to standardize the web.

The schema is a way to indicate its structure, definition of the meaning of possible elements, restrictions and other useful information for its understanding and its manipulation.

  • 2

    With your answer I finally understood the reason for Xpath text() return so many empty nodes between elements :D.

1

Each of the following fragments code-driven:

<alunos>, <aluno>, <nome>, ...

Are called tag. When we have them "complete", with a start tag and a tag of their end:

<alunos></alunos>, <aluno></aluno>, etc.

We call them elements.

Each element can have zero, one or more attributes. In your example, none of them has attribute, but just to illustrate, we could have the attribute id in <aluno>:

<aluno id="aluno_1"></aluno>

When the browser (for example) reads XML/HTML it turns it into a tree GIFT (Document Object Model). When this occurs, each element, attribute, text among other types are called knot (or object).

Below a example of an XML DOM represented by a node tree (Node-Tree):

Uma árvore de nós criada a partir de um XML

Of the following XML:

<bookstore>
   <book category="cooking">
       <title lang="en">Everyday Italian</title>
       <author>Giada De Laurentiis</author>
       <year>2005</year>
       <price>30.00</price>
    </book>
</bookstore>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.