keepassphp/lib/database.php
public static function loadFromXML($xml, iRandomStream $randomStream,
		&$error)
	{
		$reader = new ProtectedXMLReader($randomStream);
		if(!$reader->XML($xml) || !$reader->read(-1))
		{
			$error = "Database XML load: cannot parse the XML string.";
			$reader->close();
			return null;
		}
		if(!$reader->isElement(self::XML_KEEPASSFILE))
		{
			$error = "Database XML load: the root element is not '" . self::XML_KEEPASSFILE . "'.";
			$reader->close();
			return null;
		}
		$db = new Database();
		$db->parseXML($reader);
		$reader->close();
		if($db->_name == null && $db->_groups == null)
		{
			$error = "Database XML load: empty database.";
			return null;
		}
		$error = null;
		return $db;
	}
public static function loadFromXML($xml, iRandomStream $randomStream,
		&$error)
	{
		$reader = new ProtectedXMLReader($randomStream);
		if(!$reader->XML($xml) || !$reader->read(-1))
		{
			$error = "Database XML load: cannot parse the XML string.";
			$reader->close();
			return null;
		}
		if(!$reader->isElement(self::XML_KEEPASSFILE))
		{
			$error = "Database XML load: the root element is not '" . self::XML_KEEPASSFILE . "'.";
			$reader->close();
			return null;
		}
		$db = new Database();
		$db->parseXML($reader);
		$reader->close();
		if($db->_name == null && $db->_groups == null)
		{
			$error = "Database XML load: empty database.";
			return null;
		}
		$error = null;
		return $db;
	}
public static function loadFromXML ( $ xml , iRandomStream $ randomStream , & $ error ) { $ reader = new ProtectedXMLReader ( $ randomStream ) ; if ( ! $ reader -> XML ( $ xml ) || ! $ reader -> read ( - 1 ) ) { $ error = "Database XML load: cannot parse the XML string." ; $ reader -> close ( ) ; return null ; } if ( ! $ reader -> isElement ( self :: XML_KEEPASSFILE ) ) { $ error = "Database XML load: the root element is not '" . self :: XML_KEEPASSFILE . "'." ; $ reader -> close ( ) ; return null ; } $ db = new Database ( ) ; $ db -> parseXML ( $ reader ) ; $ reader -> close ( ) ; if ( $ db -> _name == null && $ db -> _groups == null ) { $ error = "Database XML load: empty database." ; return null ; } $ error = null ; return $ db ; }
Creates a new Database instance from an XML string with the format of
a KeePass 2.x database.
@param $xml An XML string.
@param $randomStream A iRandomStream instance to decrypt protected data.
@param &$error A string that will receive a message in case of error.
@return A Database instance if the parsing went okay, null otherwise.
Creates a new Database instance from an XML string with the format of a KeePass 2 . x database .