Last active
August 29, 2015 14:06
-
-
Save phpfiddle/b6bf05ab3ab4ea5f01e5 to your computer and use it in GitHub Desktop.
[ Posted by Valent ] класс для анализа XML - структуры
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A { | |
private $a, $b; | |
public function __construct($ob) { | |
$this->a = $ob->a; | |
$this->b = $ob->b; | |
} | |
public function __toString() { | |
return "a = $this->a; b = $this->b"; | |
} | |
} | |
$xml = <<<XML | |
<objects> | |
<object> | |
<a>123</a> | |
<b>124</b> | |
</object> | |
<object> | |
<a>124</a> | |
<b>125</b> | |
</object> | |
</objects> | |
XML; | |
$xml = simplexml_load_string($xml); | |
foreach ($xml->object as $ob) { | |
$a = new A($ob); | |
echo "$a<br>"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A { | |
private $a, $b; | |
public function __construct($ob) { | |
$this->a = $ob->a; | |
$this->b = $ob->b; | |
} | |
public function __toString() { | |
return "a = $this->a; b = $this->b"; | |
} | |
} | |
$xml = <<<XML | |
<objects> | |
<object> | |
<a>123</a> | |
<b>124</b> | |
</object> | |
<object> | |
<a>124</a> | |
<b>125</b> | |
</object> | |
</objects> | |
XML; | |
$xml = simplexml_load_string($xml); | |
foreach ($xml->object as $ob) { | |
$a = new A($ob); | |
echo "$a<br>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment