XML & URL Encoding
A URL, or Uniform Resource Locator, specifies the address of a resource on the Internet. Because URLs are limited to a subset of ASCII characters, it is sometimes necessary to replace "unsafe" characters with an encoded representation. In XML these encodings can be described using entities.
-
Entities in XML
-
Entities in XML begin with the ampersand (&) and pound sign (#) followed by the character encoding. The entity is terminated with a semicolon (;). For example, the encoding "%" could be used to represent the percent sign. If the character encoding is preceded with an x, the encoding is assumed to be a hex encoding. For example, "<" represents the less than (<) sign.
Predefined Entities
-
XML also defines several commonly used characters that are reserved in HTML and XML. For example, "&" represents the ampersand character. The predefined entities in XML are amp, lt, gt, apos and quot.
-
Example
-
A URL to get an RSS feed might look like the following:
http://myurl.com/rss?get="myfeed('c:\feed.xml')"
Encoding this URL yields the following results:
http://myurl.com/rss?get=%22myfeed('c:%5Cfeed.xml')%22
The XML element for this encoding would be as follows:
<myURL>http://myurl.com/rss?get=%22myfeed('c:%5Cfeed.xml')%22</myURL>
-