Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########## |
| 2 | XML Helper |
| 3 | ########## |
| 4 | |
| 5 | The XML Helper file contains functions that assist in working with XML |
| 6 | data. |
| 7 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 10 | |
Derek Jones | 65d4f7e | 2013-07-19 15:35:36 -0700 | [diff] [blame] | 11 | .. raw:: html |
| 12 | |
| 13 | <div class="custom-index container"></div> |
| 14 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 15 | Loading this Helper |
| 16 | =================== |
| 17 | |
| 18 | This helper is loaded using the following code |
| 19 | |
| 20 | :: |
| 21 | |
| 22 | $this->load->helper('xml'); |
| 23 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 24 | Available Functions |
| 25 | =================== |
| 26 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | The following functions are available: |
| 28 | |
Derek Jones | 261ba1c | 2013-07-19 16:01:32 -0700 | [diff] [blame^] | 29 | .. function:: xml_convert($str[, $protect_all = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 31 | :param string $str: the text string to convert |
| 32 | :param bool $protect_all: Whether to protect all content that looks like a potential entity instead of just numbered entities, e.g. &foo; |
Derek Jones | 22c9b80 | 2013-07-19 15:38:06 -0700 | [diff] [blame] | 33 | :returns: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 34 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 35 | Takes a string as input and converts the following reserved XML |
| 36 | characters to entities: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 37 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 38 | - Ampersands: & |
| 39 | - Less then and greater than characters: < > |
| 40 | - Single and double quotes: ' " |
| 41 | - Dashes: - |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 42 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 43 | This function ignores ampersands if they are part of existing numbered |
| 44 | character entities, e.g. {. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | |
Derek Jones | e7dfb67 | 2013-07-19 14:16:56 -0700 | [diff] [blame] | 46 | $string = '<p>Here is a paragraph & an entity ({).</p>'; |
| 47 | $string = xml_convert($string); |
| 48 | echo $string; |
| 49 | |
| 50 | outputs: |
| 51 | |
| 52 | .. code-block:: html |
| 53 | |
| 54 | <p>Here is a paragraph & an entity ({).</p> |