rummykhan/easy-xml is a Laravel package for convert your data to xml string easily..
It currently has 0 GitHub stars and 6.319 downloads on Packagist (latest version 1.0.6).
Install it with composer require rummykhan/easy-xml.
Discover more Laravel packages by rummykhan
or browse all Laravel packages to compare alternatives.
Last updated
This package helps you in converting your data to XML easily. This package is independent of any php framework. But I took care of two popular frameworks specifically
Install using composer
composer require rummykhan/easy-xml
Wit the constructor initialization you can use it any framework you may like.
$rootNode = new XmlNode('person');
$educationNode = new XmlNode('education');
$educationNode->addAttributes(['MOE' => 'SXC', 'DAE' => 'COE', 'BA' => 'UOS']);
$rootNode->addChildNode($educationNode);
$jobNode = new XmlNode('job');
$jobNode->addAttribute('first', 'https://best-bf.com');
$jobNode->addAttribute('second', 'https://infamous.ae');
$jobNode->addAttribute('third', 'https://awok.com');
$jobNode->addAttribute('fourth', 'https://helpbit.com');
$rootNode->addChildNode($jobNode)
->setDeclaration(XmlDeclaration::V1);
// since it implements php __toString() method
dd((string)$rootNode);
// OR
dd($rootNode->toString());
will output
<?xml version="1.0" encoding="UTF-8"?>
<person>
<education MOE="SXC" DAE="COE" BA="UOS" />
<job first="https://best-bf.com" second="https://infamous.ae" third="https://awok.com" fourth="https://helpbit.com" />
</person>
RummyKhan\EasyXml\XmlNode APIaddChildNodeTo add a child node to XmlNode. e.g.
$rootNode = new XmlNode('employees');
$employeeNode = new XmlNode('employee');
$rootNode->addChildNode($employeeNode);
setValueTo set the value of the node. Node can either have other node as children or it has a primitive value.
$rootNode = new XmlNode('name');
$rootNode->setValue('rummykhan');
addAttributeTo add the attribute for the xml node.
$rootNode = new XmlNode('person');
$rootNode->addAttribute('age', 30);
addAttributesTo add multiple attributes for the xml node. e.g.
$rootNode = new XmlNode('person');
$rootNode->addAttributes([
'name' => 'rummykhan',
'age' => 30
]);
setDeclarationTo set the Xml declaration
$rootNode = new XmlNode('employees');
$rootNode->setDeclaration('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>');
toStringTo convert xml single node or xml node hierarchy to xml string.
$rootNode = new XmlNode('employees');
dd($rootNode->toString());