I created xml file in my module etc folder.i want to read this xml file and store into variable as a string.
\Magento\Framework\Filesystem\Directory\Read $read
$XMLGetRequest=$this->read->readFile('here i need xml file path');
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI created xml file in my module etc folder.i want to read this xml file and store into variable as a string.
\Magento\Framework\Filesystem\Directory\Read $read
$XMLGetRequest=$this->read->readFile('here i need xml file path');
Try to use \Magento\Framework\Xml\Parser and \Magento\Framework\Module\Dir\Reader
Something like this:
class YourClass
{
/**
* @var \Magento\Framework\Module\Dir\Reader
*/
protected $moduleDirReader;
/**
* @var \Magento\Framework\Xml\Parser
*/
private $parser;
...
public function getValue()
{
$filePath = $this->moduleDirReader->getModuleDir('etc', 'Your_Module')
. '/paymentschema.xml'
$parsedArray = $this->parser->load($filePath)->xmlToArray();
return $parsedArray['xmlNodeName'];
}
}
there is actually a way to create a new configuration object in magento2 that can parse your configuration and validate it through an xsd all automatically.
I know they mentioned it in a fundamentals course but I can't find any reference now.
===UPDATE===
I think this is it: http://devdocs.magento.com/guides/v2.0/config-guide/config/config-create.html
Under Create Configuration Types