A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Spring in Action
this week in the
XML and Related Technologies
attribute vs. CDATA
Joined: Aug 12, 2006
Oct 13, 2006 11:49:00
I'm new to XML. I cannot decide if I should save information as attributes or as CDATA. Below are the two versions. Which way should I go and why?
<?xml version="1.0" encoding="UTF-8"?> <userList> <user name="_name_1" password="_password_0"/> <user name="_name_1" password="_password_1"/> <user name="_name_1" password="_password_2"/> </userList>
<?xml version="1.0" encoding="UTF-8"?> <userList> <user> <name> _name_1 </name> <password> _password_1 </password> </user> <user> <name> _name_2 </name> <password> _password_2 </password> </user> <user> <name> _name_3 </name> <password> _password_3 </password> </user> </userList>
Joined: Aug 22, 2006
Oct 25, 2006 02:29:00
You should go for the first one (the attribute version).
Reason: name and password are attributes of a user.
Only if you are not able to represent in the first method you can go for the second method.
You can go for CDATA under following situations.
It is sorta covered in the
JavaRanch Style Guide
subject: attribute vs. CDATA
Multiple ATTLIST declarations for a attribute!
Problem with security constraints while doing authentication & authorization
PCDATA and CDATA
Accessing attribute with colons
Illegal XML character �
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014