1 заметка с тегом
XML
XML: Читаем и пишем с namespaces
10 июля 2015, 10:32
Пишем XML
$xmlService = new Sabre\Xml\Service(); $xmlService->namespaceMap = ['http://example.org' => 'b']; $xmlService->write('{http://example.org}book', [ '{http://example.org}title' => 'Cryptonomicon', '{http://example.org}author' => 'Neil Stephenson', ]);
Результат
<?xml version="1.0"?> <b:book xmlns:b="http://example.org"> <b:title>Cryptonomicon</b:title> <b:author>Neil Stephenson</b:author> </b:book>
Читаем XML
<?php $input = <<<XML <article xmlns="http://example.org/"> <title>Hello world</title> <content>Fuzzy Pickles</content> </article> XML; $service = new Sabre\Xml\Service(); $service->elementMap = [ '{http://example.org/}article' => 'Sabre\Xml\Element\KeyValue', ]; print_r($service->parse($input));
Результат
Array ( [{http://example.org/}title] => Hello world [{http://example.org/}content] => Fuzzy Pickles )