1

I am a beginner in XML language. I am learning XML in Android studio at school.

Example,

<Person>
 <sex ="female"></sex>
 <firstname = "Hani"></firstname>
 <lastname = "Jeong"></lastname>
</Person>

in this case, all the values are hidden from users, right?

What I am really confused about is that I understood that attributes must always have values.

Which common situations do you hide the values or show the values to users?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
In-young Choung
  • 779
  • 2
  • 8
  • 22
  • **Example #3 is not [well-formed](http://stackoverflow.com/a/25830482/290085), but, overall, this is a [duplicate](http://stackoverflow.com/questions/33746/xml-attribute-vs-xml-element)...** – kjhughes Feb 15 '16 at 18:48
  • Thanks for the resource. Sorry I realized that some of questions were duplicate as you mentioned. – In-young Choung Feb 16 '16 at 00:53
  • Your edit moves your question away from being a duplicate but still doesn't address the problem of your XML still being not well-formed. I'll try to explain in an answer below, but you ought to do some basic introductory XML reading. Thanks. – kjhughes Feb 16 '16 at 01:32

1 Answers1

2

Your XML is not well-formed.

You'll have to change it to use elements,

<Person>
 <sex>female</sex>
 <firstname>Hani</firstname>
 <lastname>Jeong</lastname>
</Person>

or attributes,

<Person sex="female"
        firstname="Hani"      
        lastname="Jeong"/>

or some combination thereof.

See also: XML attribute vs XML element

What I am really confused about is that I understood that attributes must always have values.

Yes, for example, this would not be allowed:

<Person sex/>

But note that these could be ok,

<Person sex=""/>
<Person sex="unknown"/>

As could omitting the attribute altogether,

<Person/>

Which common situations do you hide the values or show the values to users?

The above alternatives are design choices that depend upon your data, your intent, and any associated schemas or conventions you seek to follow.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240