Reputation: 85318
I'm using XML for a config file in PHP (Using SimpleXML), in creating the config file what is more of a standard.
Having all values in elements or using the attributes?
Elements Example:
<database>
<user>test-user</user>
<pass>test-pass</pass>
</database>
Attribute Example:
<database user="test-user" pass="test-pass"></database>
Are there any benefits of either way?
Also other languages might need to read the same config file, such as Java and Perl.
Upvotes: 3
Views: 1009
Reputation: 157892
XML was invented to be a human-readable format, but it's so formalized that no one dares to edit it manually or even read it.
As no one would read it, I'd suggest to use PHP itself.
<?
$config['db']['user']="user";
$config['db']['pass']="pass";
?>
It's slightly more secure and reliable.
Upvotes: -2
Reputation: 23098
The oldest question asked by adopters of XML is when to use elements and when to use attributes in XML design. As with most design issues, this question rarely has absolute answers, but developers have also experienced a lack of very clear guidelines to help them make this decision.
See Principles of XML design: When to use elements versus attributes by IBM. Pretty nice article.
Here's a snippet:
In my experience working with users of XML, the first question is by far the most common. In some cases the answer is pretty unambiguous:
Upvotes: 3