What is the difference between element and attribute in xml




















Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data. A markup language implies that the data is text, marked up with metadata about structure or formatting. Here, the distinction between elements and attributes is clear.

Learn more. Asked 12 years ago. Active 3 years, 4 months ago. Viewed 40k times. I'm new to XSD, and I'm quite confused as to when to use attribute, and when to use element? Why cant we specify minOccurs and maxOccurs in attribute? Improve this question. BradleyDotNET Add a comment. Active Oldest Votes. Improve this answer. Richard Wallace 3 3 3 bronze badges. To specify that the attribute is required, use the use attribute: e. Kanagavelu Sugumar Kanagavelu Sugumar Working links for Elements and Attributes — G.

An attribute is a descriptor. It can't contain anything and can only be a simple type. Kirk Broadhurst Kirk Broadhurst Sign up or log in Sign up using Google. Sign up using Facebook. In the first example sex is an attribute. In the last, sex is a child element.

Both examples provide the same information. There are no rules about when to use attributes, and when to use child elements. Use child elements if the information feels like data. If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data.



0コメント

  • 1000 / 1000