Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.42 KB

Read.md

File metadata and controls

49 lines (40 loc) · 1.42 KB

Back

Read

XML code

<?xml version="1.0" encoding="utf-8"?>
<gen:main xmlns:gen="http://www.w3.org/2001/XMLSchema">
	<gen:ID>1000</gen:ID>
	<gen:NAME>Maim entity</gen:NAME>
	<gen:ITEM ATTR="First attribute">
		<gen:ITEM_ID>1</gen:ITEM_ID>
		<gen:ITEM_NAME>First item entity</gen:ITEM_NAME>
	</gen:ITEM>
	<gen:ITEM ATTR="Second attribute">
		<gen:ITEM_ID>2</gen:ITEM_ID>
		<gen:ITEM_NAME>Second item entity</gen:ITEM_NAME>
	</gen:ITEM>
	<gen:ITEM ATTR="Third attribute">
		<gen:ITEM_ID>3</gen:ITEM_ID>
		<gen:ITEM_NAME>Third item entity</gen:ITEM_NAME>
	</gen:ITEM>
</gen:main>

Entity read

use Matraux\XmlOrm\Xml\SimpleExplorer;

$explorer = SimpleExplorer::fromString($xml);
$main = MainEntity::fromExplorer($explorer); // Tell explorer where to start --> $explorer->withIndex('main', new GeneralXmlNamespace())

echo $main->id; // (int) 1000
echo $main->name; // (string) Maim entity

foreach($main->items as $item) {
	echo $item->id; // (int) 1, 2, 3
	echo $item->name; // (string) First item entity | Second item entity | Third item entity
	echo $item->attr; // (string) First attribute | Second attribute | Third attribute
}

echo $main->items[1]->name; // (string) First item entity
echo $main->items[3]->name; // (string) Third item entity

echo count($main->items); // (int) 3

echo $main; // (string) gen:main
echo $main->items[1]; // (string) gen:item