0

What is the difference between encoding and entity references in xml ?

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78

1 Answers1

1

Encoding refers to the way a character is represented by a sequence of bytes. It happens at a pretty low level in the processing chain: you read in the bytes and use the encoding to convert to a stream of characters. ASCII, Latin-1, and UTF-8 are all examples of encodings.

Entity references are handled by the XML parser itself. A sequence of characters, starting with & and ending with ;, is used to represent a different sequence of characters (usually just one). This happens at a fairly high level, conceptually "after" the XML parser has determined where tags are. This is why < turns into a plain old less than sign, not the beginning of a tag.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
  • so if i replace '%' with '%' is that encoding or entity reference? – SoftwareGeek Nov 03 '11 at 02:45
  • @SoftwareGeek That's an entity reference. The word "encoding" could also be used to describe an entity reference in the sense that it is a way of "encoding" things in the English language sense, but normally when people use the word encoding in this sort of context they mean a character encoding, which this isn't. – Laurence Gonsalves Nov 03 '11 at 03:35