Recommend this page to a friend! |
Classes of István Dombi | Webdice Utilities | xml_parser_example.php | Download |
|
Download <?php / * Creaated by Dombi István <dombi.istvan@webdice.hu> <dombiistvan28@gmail.com> */ //only if you dont have composer //require_once dirname(__FILE__) . '/vendor/autoload.php'; //pass the xml file like this $parser = new \Webdice\Utilities\Xml\Parser('test.xml'); //absolute URL or realive to dirname(__FILE__) $arr = $parser->parse(); //var_dump($arr); //or parse the string directly like this $parser = new \Webdice\Utilities\Xml\Parser(); $arr = $parser->parseString('<root_element><items><item attributex="1">dsa</item></items></root_element>'); //var_dump($arr); //you can also change the return array keys like this, !before the parse method $parser = new \Webdice\Utilities\Xml\Parser('test.xml'); $parser->changeNodeConfig('element_name', 'children_elements', 'attributes'); $arr = $parser->parse(null); //var_dump($arr); //you can change format between JSON and ARRAY like this $parser = new \Webdice\Utilities\Xml\Parser(); $parser->changeNodeConfig('element_name', 'children_elements', 'attributes'); $arr = $parser->parse('test.xml', \Webdice\Utilities\Xml\Parser::TYPE_JSON); //and you can write xml from array recursively $parser = new \Webdice\Utilities\Xml\Parser(); $content = $parser->toXml(
); |