zeanwork.com.br  >>  Documentação  >>  Components  >>  XML Creator
XML Creator
O component xmlCreator serve criar XMLs simples.


Carregando o component

Para você utilizar este component, você prescisa definir que irá utiliza-lo. Veja mais em: Controllers > Carregando models, components, helpers e extensions.
O nome deste component é xmlCreator, este é o nome que você irá utilizar para carrega-lo.


Começando a escrever o XML

write()
Este método inicia a escrita do XML.

Parâmetros:
string $indent [opcional]
Identação do XML.



Veja exemplo:
public function index(){
	$this->xmlCreator->write();
}



Iniciando um novo nó

childStart()
Este método inicia um novo nó.

Parâmetros:
string $childName
Nome do nó.

array $attrs [opcional]
Atributos para o nó.



Veja exemplo:
public function index(){
	$this->xmlCreator->write();
	$this->xmlCreator->childStart('rss', array('version' => '2.0'));
}



Finalizando um nó

childEnd()
Este método finaliza o ultimo nó iniciado.

Veja exemplo:
public function index(){
	$this->xmlCreator->write();
	$this->xmlCreator->childStart('rss', array('version' => '2.0'));
	$this->xmlCreator->childEnd();
}



Criando um elemento

element()
Este método cria um elemento.

Parâmetros:
string $elementName
Nome do elemento.

mixwed $content
Conteúdo para o elemento.

array $attrs [opcional]
Atributos para o elemento.



Veja exemplo:
public function index(){
	$this->xmlCreator->write();
	$this->xmlCreator->childStart('rss', array('version' => '2.0'));
		$this->xmlCreator->childStart('item');
			$this->xmlCreator->element('title', 'Zeanwork Framework PHP');
		$this->xmlCreator->childEnd();
	$this->xmlCreator->childEnd();
}



Resgatando o XML

getXml()
Este método retorna toda a estrutura do XML.

Retorno:
string
String contendo toda a estrutura do XML.



Veja exemplo:
public function index(){
	$this->xmlCreator->write();
	$this->xmlCreator->childStart('rss', array('version' => '2.0'));
		$this->xmlCreator->childStart('item');
			$this->xmlCreator->element('title', 'Zeanwork Framework PHP');
		$this->xmlCreator->childEnd();
	$this->xmlCreator->childEnd();
	echo $this->xmlCreator->getXml();
}



Salvando o XML em um arquivo

save()
Este método salva toda a estrutura do XML em um arquivo.

Parâmetros:
string $path
Nome/caminho do arquivo a ser salvo.



Veja exemplo:
public function index(){
	$this->xmlCreator->write();
	$this->xmlCreator->childStart('rss', array('version' => '2.0'));
		$this->xmlCreator->childStart('item');
			$this->xmlCreator->element('title', 'Zeanwork Framework PHP');
		$this->xmlCreator->childEnd();
	$this->xmlCreator->childEnd();
	echo $this->xmlCreator->save(PUBLIC . 'rss.xml');
}