english/libraries/joomla/form/form.php
/**
	 * Method to load the form description from an XML string or object.
	 *
	 * The replace option works per field.  If a field being loaded already exists in the current
	 * form definition then the behavior or load will vary depending upon the replace flag.  If it
	 * is set to true, then the existing field will be replaced in its exact location by the new
	 * field being loaded.  If it is false, then the new field being loaded will be ignored and the
	 * method will move on to the next field to load.
	 *
	 * @param   string  $data     The name of an XML string or object.
	 * @param   string  $replace  Flag to toggle whether form fields should be replaced if a field
	 *                            already exists with the same group/name.
	 * @param   string  $xpath    An optional xpath to search for the fields.
	 *
	 * @return  boolean  True on success, false otherwise.
	 *
	 * @since   11.1
	 */
Method to load the form description from an XML string or object.
The replace option works per field.  If a field being loaded already exists in the current
form definition then the behavior or load will vary depending upon the replace flag.  If it
is set to true, then the existing field will be replaced in its exact location by the new
field being loaded.  If it is false, then the new field being loaded will be ignored and the
method will move on to the next field to load.

@param   string  $data     The name of an XML string or object.
@param   string  $replace  Flag to toggle whether form fields should be replaced if a field
already exists with the same group/name.
@param   string  $xpath    An optional xpath to search for the fields.

@return  boolean  True on success, false otherwise.


Method to load the form description from an XML string or object . The replace option works per field . If a field being loaded already exists in the current form definition then the behavior or load will vary depending upon the replace flag . If it is set to true then the existing field will be replaced in its exact location by the new field being loaded . If it is false then the new field being loaded will be ignored and the method will move on to the next field to load . @param string $data The name of an XML string or object . @param string $replace Flag to toggle whether form fields should be replaced if a field already exists with the same group / name . @param string $xpath An optional xpath to search for the fields . @return boolean True on success false otherwise .
public function load($data, $replace = true, $xpath = false)
	{
		if ((!($data instanceof JXMLElement)) && (!is_string($data))) {
			return false;
		}
		if (is_string($data)) {
			$data = JFactory::getXML($data, false);
			if (!$data) {
				return false;
			}
		}
		if (empty($this->xml)) {
			if (!$xpath && ($data->getName() == 'form')) {
				$this->xml = $data;
				$this->syncPaths();
				return true;
			}
			else {
				$this->xml = new JXMLElement('<form></form>');
			}
		}
		$elements = array();
		if ($xpath) {
			$elements = $data->xpath($xpath);
		}
		elseif ($data->getName() == 'form') {
			$elements = $data->children();
		}
		if (empty($elements)) {
			return true;
		}
		foreach ($elements as $element)
		{
			$fields = $element->xpath('descendant-or-self::field');
			foreach ($fields as $field)
			{
				$attrs	= $field->xpath('ancestor::fields[@name]/@name');
				$groups	= array_map('strval', $attrs ? $attrs : array());
				if ($current = $this->findField((string) $field['name'], implode('.', $groups))) {
					if ($replace) {
						$dom = dom_import_simplexml($current);
						$dom->parentNode->removeChild($dom);
					}
					else {
						unset($field);
					}
				}
			}
			self::addNode($this->xml, $element);
		}
		$this->syncPaths();
		return true;
	}
public function load ( $ data , $ replace = true , $ xpath = false ) { if ( ( ! ( $ data instanceof JXMLElement ) ) && ( ! is_string ( $ data ) ) ) { return false ; } if ( is_string ( $ data ) ) { $ data = JFactory :: getXML ( $ data , false ) ; if ( ! $ data ) { return false ; } } if ( empty ( $ this -> xml ) ) { if ( ! $ xpath && ( $ data -> getName ( ) == 'form' ) ) { $ this -> xml = $ data ; $ this -> syncPaths ( ) ; return true ; } else { $ this -> xml = new JXMLElement ( '<form></form>' ) ; } } $ elements = array ( ) ; if ( $ xpath ) { $ elements = $ data -> xpath ( $ xpath ) ; } elseif ( $ data -> getName ( ) == 'form' ) { $ elements = $ data -> children ( ) ; } if ( empty ( $ elements ) ) { return true ; } foreach ( $ elements as $ element ) { $ fields = $ element -> xpath ( 'descendant-or-self::field' ) ; foreach ( $ fields as $ field ) { $ attrs = $ field -> xpath ( 'ancestor::fields[@name]/@name' ) ; $ groups = array_map ( 'strval' , $ attrs ? $ attrs : array ( ) ) ; if ( $ current = $ this -> findField ( ( string ) $ field [ 'name' ] , implode ( '.' , $ groups ) ) ) { if ( $ replace ) { $ dom = dom_import_simplexml ( $ current ) ; $ dom -> parentNode -> removeChild ( $ dom ) ; } else { unset ( $ field ) ; } } } self :: addNode ( $ this -> xml , $ element ) ; } $ this -> syncPaths ( ) ; return true ; }
Method to load the form description from an XML string or object.
Method to load the form description from an XML string or object .
// If the data to load isn't already an XML element or string return false. // Attempt to load the XML if a string. // Make sure the XML loaded correctly. // If we have no XML definition at this point let's make sure we get one. // If no XPath query is set to search for fields, and we have a <form />, set it and return. // Synchronize any paths found in the load. // Create a root element for the form. // Get the XML elements to load. // If there is nothing to load return true. // Load the found form elements. // Get an array of fields with the correct name. // Get the group names as strings for ancestor fields elements. // Check to see if the field exists in the current form. // If set to replace found fields remove it from the current definition. // Else remove it from the incoming definition so it isn't replaced. // Merge the new field data into the existing XML document. // Synchronize any paths found in the load.