XMLオブジェクトを配列に入れようとしていますが、空の配列が表示され、その理由がわかりません。
<?php
$string = '<?xml version="1.0" encoding="UTF-8"?>
<confgs>
# System Settings #
############################################################
## Login Account Settings
ADMIN_ID="<confg rang="0" soort="veld" name="config1" />"
ADMIN_ID="<confg rang="1" soort="veld" name="config2" />"
ADMIN_PASS="PKXUT1xxRoutIT"
USER_ID="<confg rang="2" soort="veld" name="config3" />"
USER_PASS="<confg rang="3" soort="optie" opties="opt1~opt2~opt3" name="config4" />"
## Time Adjust Settings
TIME_ZONE="60"
DST_ENABLE="Y"
MAC_ADRES="<confg rang="4" soort="veld" name="config5" />"
DST_START_MONTH="3"
DST_START_ORDINAL_DAY="<stconfg rang="1" soort="veld" name="stanconf1" />"
DST_START_ORDINAL_DAY="<confg rang="8" soort="optie" opties="deze~die~endit~optie~extra" name="kijkhetwerkt" />"
DST_START_ORDINAL_DAY="5"
DST_START_ORDINAL_DAY="<stconfg rang="2" soort="veld" name="stanconf2" />"
DST_START_ORDINAL_DAY="<confg rang="5" soort="veld" name="config6" />"
DST_START_ORDINAL_DAY="<confg rang="6" soort="optie" opties="dit~dat~bibobla" name="slelect" />"
IETS_CONF_ORDINAL_CFG="<confg rang="7" soort="veld" name="ditveld" />"
IETS_CONF_ORDINAL_CFG="<confg rang="9" soort="veld" name="hallo" />"
</confgs>
';
error_reporting(E_ALL ^ E_NOTICE);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXML($string);
$confg = $dom->getElementsByTagName('confg');
$form = array();
$a = 0;
foreach($confg as $configuratie){
$a++;
$form[$a] = $dom->saveXML($configuratie);
}
print_r($form);
?>
これは私が得るものです:
配列([1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] =>)
私のコードは10個の要素すべてをループしているので、そこにある必要があると何かが教えてくれます。どうすればそれを取得できますか?