Click here to Skip to main content
14,641,662 members
Rate this:
Please Sign up or sign in to vote.
See more:
I’m trying to make a XML file, but the now the problem comes. I can now see that some are using Elements like: <name>John</name> and someone likes to do it this way between quotation marks <name =”John”>.
What is the different between this and that way of doing these two coding and what are they called?
Is one way better than the other?

[edit] Unnecessary code tags removed - nelek [/edit]
Updated 19-Apr-12 11:43am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

In XML <name =”John”> is not syntactically correct. It should be something like this
<person name="John"></person>

Then person is called element and name is called the attribute of the element person. As said in the question the other way of doing this is

Here, name is the child element of the element person.
Both, give the information. There are no hard and fast rules regarding when to use as an attribute and when to use as child element. But, as a general the attribute can be used when the information concerned describes something about the element concerned, like an adjective describes about a noun. On the other hand an element can be used when the information concerned is like data.
The other difference is that if it is represented as an element then it can nest other elements and also can have attributes. But, if it is given as an attribute then it cannot have child elements and other attributes.
An explanation is given here[^][^]
I think it may be helpful.
meaeg 19-Apr-12 21:00pm
I know this ”John” would make a syntax error sinse I wrote it in word. Thank you for the answer it was helpful.
VJ Reddy 19-Apr-12 21:08pm
If the answer is helpful, then you can consider to vote and accept the solution.
Thank you for the response :)
Sergey Alexandrovich Kryukov 22-Apr-12 21:00pm
All correct, my 5 (in my edition, I only removed invalid '.' after </pre>)
VJ Reddy 22-Apr-12 21:08pm
Thank you very much, SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100