Click here to Skip to main content
15,896,467 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi!
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]
Posted
Updated 19-Apr-12 11:43am
v2

1 solution

In XML <name =”John”> is not syntactically correct. It should be something like this
HTML
<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
HTML
<person>
    <name>John</name>
</person>

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
http://www.w3schools.com/dtd/dtd_el_vs_attr.asp[^]
http://msdn.microsoft.com/en-us/library/7f0tkwcx(v=vs.80).aspx[^]
I think it may be helpful.
 
Share this answer
 
v3
Comments
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>)
--SA
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900