XML element or attribute?
-
Dear I have a question about how to use attribute or element. Recently when I desige the XML data map, I am confusing that when should I attribute , when should I use element. For example, I have "Login" root element. Inside the Login, I want to put username and password. So, Should I make an child element "username" and "password"? Or should I put attribute "username" and "password" under the root element "Login"?? Well, it seems not much different between two. But in many case, I always think about Should I use this field for attribute or for child element? Is there any general rules can help me to choose between attribute and element? such as if the data size is large, we should use........etc How does it affect the application performance? regards Davis :confused: Davis Leung Analyst Programmer Fedex
-
Dear I have a question about how to use attribute or element. Recently when I desige the XML data map, I am confusing that when should I attribute , when should I use element. For example, I have "Login" root element. Inside the Login, I want to put username and password. So, Should I make an child element "username" and "password"? Or should I put attribute "username" and "password" under the root element "Login"?? Well, it seems not much different between two. But in many case, I always think about Should I use this field for attribute or for child element? Is there any general rules can help me to choose between attribute and element? such as if the data size is large, we should use........etc How does it affect the application performance? regards Davis :confused: Davis Leung Analyst Programmer Fedex
No there are no rules for what should be an attribute and what should be an element. It's just up to you to decide what would work better for you application. Generally though an attribute should be one or two words, anything more should be an element. Another thing to consider is how you may need to use document. If for example you have a name element with child elements for first name and last name you could obtain the nodes by first or last name, or just the name nodes. You could do the same thing with attrbutes but not as cleanly in my opinion.