本文整理汇总了PHP中Sabre\Xml\Reader::xml方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::xml方法的具体用法?PHP Reader::xml怎么用?PHP Reader::xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\Xml\Reader
的用法示例。
在下文中一共展示了Reader::xml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
function parse($xml, array $elementMap = [])
{
$reader = new Reader();
$reader->elementMap = array_merge($this->elementMap, $elementMap);
$reader->xml($xml);
return $reader->parse();
}
示例2: testDeserialize
function testDeserialize()
{
$input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
<listThingy>
<elem1 />
<elem2 />
<elem3 />
<elem4 attr="val" />
<elem5>content</elem5>
<elem6><subnode /></elem6>
</listThingy>
<listThingy />
<otherThing>
<elem1 />
<elem2 />
<elem3 />
</otherThing>
</root>
BLA;
$reader = new Reader();
$reader->elementMap = ['{http://sabredav.org/ns}listThingy' => 'Sabre\\Xml\\Element\\Elements'];
$reader->xml($input);
$output = $reader->parse();
$this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}listThingy', 'value' => ['{http://sabredav.org/ns}elem1', '{http://sabredav.org/ns}elem2', '{http://sabredav.org/ns}elem3', '{http://sabredav.org/ns}elem4', '{http://sabredav.org/ns}elem5', '{http://sabredav.org/ns}elem6'], 'attributes' => []], ['name' => '{http://sabredav.org/ns}listThingy', 'value' => [], 'attributes' => []], ['name' => '{http://sabredav.org/ns}otherThing', 'value' => [['name' => '{http://sabredav.org/ns}elem1', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem2', 'value' => null, 'attributes' => []], ['name' => '{http://sabredav.org/ns}elem3', 'value' => null, 'attributes' => []]], 'attributes' => []]], 'attributes' => []], $output);
}
示例3: parse
function parse($xml)
{
$reader = new Reader();
$reader->elementMap['{DAV:}root'] = 'Sabre\\DAVACL\\Xml\\Property\\CurrentUserPrivilegeSet';
$reader->xml($xml);
$result = $reader->parse();
return $result['value'];
}
示例4: read
public function read($path)
{
parent::read($path);
$reader = new Reader();
$reader->xml($this->contents);
$this->parsed = $reader->parse();
return $this;
}
示例5: testParseReturnsArray
public function testParseReturnsArray()
{
$rw = new Realworks();
$xmlString = file_get_contents('example.xml');
$reader = new XML\Reader();
$reader->xml($xmlString);
$output = $reader->parse();
$objects = $rw->parse($output);
$this->assertInternalType('array', $objects);
}
示例6: map
/**
* Build a response object
*
* @param \GuzzleHttp\Psr7\Response $response
* @return Activity[]
*/
public function map(Response $response)
{
// Pares XML
$reader = new Reader();
$reader->xml($response->getBody());
$parse = $reader->parse();
$return = [];
foreach ($parse['value'] as $value) {
$return[] = new Activity($value['attributes'], $value['value']);
}
return $return;
}
示例7: read
protected function read($xmlFile)
{
$xml_contents = file_get_contents($xmlFile);
$reader = new Reader();
$reader->xml($xml_contents);
$tree = $reader->parse();
foreach ($tree['value'] as $node) {
$key = $node['attributes']['name'];
$value = $node['value'];
$this->patterns[$key] = $value;
}
}
示例8: testDeserialize
/**
* @expectedException \LogicException
*/
function testDeserialize()
{
$input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
<blabla />
</root>
BLA;
$reader = new Reader();
$reader->elementMap = ['{http://sabredav.org/ns}blabla' => 'Sabre\\Xml\\Element\\Cdata'];
$reader->xml($input);
$output = $reader->parse();
}
示例9: testDeserialize
/**
* @dataProvider xmlProvider
*/
function testDeserialize($input, $expected)
{
$input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
<fragment>{$input}</fragment>
</root>
BLA;
$reader = new Reader();
$reader->elementMap = ['{http://sabredav.org/ns}fragment' => 'Sabre\\Xml\\Element\\XmlFragment'];
$reader->xml($input);
$output = $reader->parse();
$this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}fragment', 'value' => new XmlFragment($expected), 'attributes' => []]], 'attributes' => []], $output);
}
示例10: testDeserialize
function testDeserialize()
{
$input = <<<BLA
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns">
<uri>/foo/bar</uri>
</root>
BLA;
$reader = new Reader();
$reader->contextUri = 'http://example.org/';
$reader->elementMap = ['{http://sabredav.org/ns}uri' => 'Sabre\\Xml\\Element\\Uri'];
$reader->xml($input);
$output = $reader->parse();
$this->assertEquals(['name' => '{http://sabredav.org/ns}root', 'value' => [['name' => '{http://sabredav.org/ns}uri', 'value' => new Uri('http://example.org/foo/bar'), 'attributes' => []]], 'attributes' => []], $output);
}
示例11: testDeserializeValueObjectEmpty
function testDeserializeValueObjectEmpty()
{
$input = <<<XML
<?xml version="1.0"?>
<foo xmlns="urn:foo" />
XML;
$reader = new Reader();
$reader->xml($input);
$reader->elementMap = ['{urn:foo}foo' => function (Reader $reader) {
return valueObject($reader, 'Sabre\\Xml\\Deserializer\\TestVo', 'urn:foo');
}];
$output = $reader->parse();
$vo = new TestVo();
$expected = ['name' => '{urn:foo}foo', 'value' => $vo, 'attributes' => []];
$this->assertEquals($expected, $output);
}
示例12: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
$reader = new Reader();
// Wrapping the xml in a container, so root-less values can still be
// parsed.
$xml = <<<XML
<?xml version="1.0"?>
<xml-fragment xmlns="http://sabre.io/ns">{$this->getXml()}</xml-fragment>
XML;
$reader->xml($xml);
$elementNamespace = null;
while ($reader->read()) {
if ($reader->depth < 1) {
// Skipping the root node.
continue;
}
switch ($reader->nodeType) {
case Reader::ELEMENT:
$writer->startElement($reader->getClark());
$empty = $reader->isEmptyElement;
while ($reader->moveToNextAttribute()) {
switch ($reader->namespaceURI) {
case '':
$writer->writeAttribute($reader->localName, $reader->value);
break;
case 'http://www.w3.org/2000/xmlns/':
// Skip namespace declarations
break;
default:
$writer->writeAttribute($reader->getClark(), $reader->value);
break;
}
}
if ($empty) {
$writer->endElement();
}
break;
case Reader::CDATA:
case Reader::TEXT:
$writer->text($reader->value);
break;
case Reader::END_ELEMENT:
$writer->endElement();
break;
}
}
}
示例13: loadFilename
public static function loadFilename($filename)
{
$xml_contents = file_get_contents($filename);
$reader = new Reader();
/**
* Loading components
*/
$components_list = array();
$components = scandir(__DIR__ . '/../../Component/');
foreach ($components as $file) {
if ($file[0] == '.') {
continue;
}
if (substr($file, -4) != '.php') {
continue;
}
$componentName = substr($file, 0, -strlen('Component.php'));
$components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = 'Biome\\Component\\' . $componentName . 'Component';
}
$components_dirs = \Biome\Biome::getDirs('components');
$components_dirs = array_reverse($components_dirs);
foreach ($components_dirs as $dir) {
if (!file_exists($dir)) {
continue;
}
$components = scandir($dir);
foreach ($components as $file) {
if ($file[0] == '.') {
continue;
}
if (substr($file, -4) != '.php') {
continue;
}
$componentName = substr($file, 0, -strlen('Component.php'));
$components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = $componentName . 'Component';
}
}
$reader->elementMap = $components_list;
/**
* Parsing XML template
*/
$reader->xml($xml_contents);
$tree = $reader->parse();
return $tree;
}
示例14: check
public function check(Request $request)
{
// Check if Domain Name is available via API
$domain = Domains::cleanURL(strtolower($request->input('domain')));
// International Domain Names//
if (Domains::isDomainIntl($domain)) {
InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz');
$status = InternetBS::api()->domainCheck($domain);
if ($status) {
$message = 'Domain Name is available';
}
$message = 'Domain Name is not available';
return ['message' => $message, 'status' => $status];
}
// Rwandan Domain Names
if (Domains::isDomainRW($domain)) {
$params = ['form_params' => ['search' => $domain], 'verify' => false];
$data = Domains::post('https://whois.ricta.org.rw/whois.jsp', $params);
if (preg_match_all('/<tr><th>(?:[a-zA-Z\\s]+)<\\/th><td><a href=\'(.+)\'>(?:[a-zA-Z\\.]+)<\\/a>/im', $data, $matches)) {
$status = false;
$message = 'Domain Name is not available';
} else {
$message = 'Domain Name is available';
$status = true;
}
return ['message' => $message, 'status' => $status];
}
// Ugandan Domain Names
if (Domains::isDomainUG($domain)) {
$xml = (string) Domains::post('https://new.registry.co.ug:8006/api', ['body' => Domains::UG_Whois_Command($domain)]);
$reader = new Reader();
$reader->xml($xml);
$parsedXML = $reader->parse();
$data = $parsedXML['value'];
$status = (int) $parsedXML['attributes']['status'];
if ($status) {
$status = false;
$message = 'Domain Name is Not available';
} else {
$message = 'Domain Name is available';
$status = true;
}
return ['message' => $message, 'status' => $status];
}
}
示例15: handle
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Avoid PHP timeouts when querying large clusters
set_time_limit(0);
//Create Sabre XML Reader Object
$reader = new Reader();
//Create Guzzle REST client Object
$client = new Client(['headers' => ['Accept' => 'application/xml', 'Content-Type' => 'application/xml']]);
//Pick up the csv report created in the calling controller
$csvFile = new CsvFile($this->csvFileName);
//Write the csv headers
$csvFile->writeRow(explode(',', $this->csv_headers));
//Loop the devices in $this->deviceList to get firmware info
foreach ($this->deviceList as $device) {
//Only get firmware if the device is registered
if ($device['IsRegistered']) {
\Log::debug('Running with', [$device]);
try {
//Query the phones web interface for the XML device info
$response = $client->get('http://' . $device['IpAddress'] . '/DeviceInformationX', ['connect_timeout' => 2]);
} catch (RequestException $e) {
\Log::debug('Phone request exception', [$e]);
continue;
}
$body = $response->getBody()->getContents();
\Log::debug('XML:', [$body]);
//Consume the XML with Sabre XML Reader
if ($reader->xml($body)) {
//Parse the XML
$deviceInfoX = $response = $reader->parse();
} else {
\Log::debug('Error, there was no XML', []);
}
//Find the index for XML key holding the Firmware information
$index = searchMultiDimArray($deviceInfoX['value'], 'name', '{}versionID');
//Place the firmware info into our $device array
$device['Firmware'] = $deviceInfoX['value'][$index]['value'];
}
//Write the firmware info to csv
$csvFile->writeRow($device);
}
}