-
Notifications
You must be signed in to change notification settings - Fork 43
/
example1.php
50 lines (43 loc) · 1.37 KB
/
example1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
header ("Content-type: text/html, charset=utf-8;");
require_once dirname(__FILE__). "/../library/SimpleXMLReader.php";
class ExampleXmlReader1 extends SimpleXMLReader
{
public function __construct()
{
// by node name
$this->registerCallback("Цена", array($this, "callbackPrice"));
// by xpath
$this->registerCallback("/Данные/Остатки/Остаток", array($this, "callbackRest"));
}
protected function callbackPrice($reader)
{
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$ref = (string) $attributes->{"Номенклатура"};
if ($ref) {
$price = floatval((string)$xml);
$xpath = $this->currentXpath();
echo "$xpath: $ref = $price;\n";
}
return true;
}
protected function callbackRest($reader)
{
$xml = $reader->expandSimpleXml();
$attributes = $xml->attributes();
$ref = (string) $attributes->{"Номенклатура"};
if ($ref) {
$rest = floatval((string) $xml);
$xpath = $this->currentXpath();
echo "$xpath: $ref = $rest;\n";
}
return true;
}
}
echo "<pre>";
$file = dirname(__FILE__) . "/example1.xml";
$reader = new ExampleXmlReader1;
$reader->open($file);
$reader->parse();
$reader->close();