Проблема с Dom Xml
Trying to get property of non-object in z:\home\localhost\www\lab8\func.inc on line 25
Подскажите плз, где ошибка?
Код:
<?xml version="1.0" encoding="Windows-1251"?>
<task-list xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="task-list.xsd">
<task deadline="2005-10-31">
<fio>Zayonchkisky Victor Petrovich</fio>
<theme>Synchronization of GSM-networks</theme>
<input-data>
<input-data-item>Covered zone</input-data-item>
<input-data-item>Number of BSs</input-data-item>
<input-data-item>Maximal creeping</input-data-item>
</input-data>
<content>
<content-item>1. Calculation of frequency deviation</content-item>
<content-item>2. Calculation of creeping frequency</content-item>
</content>
<graphics-list>
<graphics>Im. 1</graphics>
<graphics>Im. 2</graphics>
<graphics>Im. 3</graphics>
<graphics>Im. 4</graphics>
</graphics-list>
<consulting section="1">Ivanov</consulting>
<consulting section="2">Petrov</consulting>
<calendar-plan section="1" begin-date="2005-09-01" end-date="2005-09-20"/>
<calendar-plan section="2" begin-date="2005-09-03" end-date="2005-09-20"/>
</task>
</task-list>
<task-list xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="task-list.xsd">
<task deadline="2005-10-31">
<fio>Zayonchkisky Victor Petrovich</fio>
<theme>Synchronization of GSM-networks</theme>
<input-data>
<input-data-item>Covered zone</input-data-item>
<input-data-item>Number of BSs</input-data-item>
<input-data-item>Maximal creeping</input-data-item>
</input-data>
<content>
<content-item>1. Calculation of frequency deviation</content-item>
<content-item>2. Calculation of creeping frequency</content-item>
</content>
<graphics-list>
<graphics>Im. 1</graphics>
<graphics>Im. 2</graphics>
<graphics>Im. 3</graphics>
<graphics>Im. 4</graphics>
</graphics-list>
<consulting section="1">Ivanov</consulting>
<consulting section="2">Petrov</consulting>
<calendar-plan section="1" begin-date="2005-09-01" end-date="2005-09-20"/>
<calendar-plan section="2" begin-date="2005-09-03" end-date="2005-09-20"/>
</task>
</task-list>
Функция обработки
Код:
// Ф-я вывода исходного документа XML
function viewDoc($a)
{
global $output;
include 'unicode.inc';
if (!empty($a) && file_exists($a))
{
$dom = new domDocument ('1.0', Encoding);
$dom -> preserveWhiteSpace = false;
$dom -> load($a);
$task_list = $dom -> documentElement; // корневой элемент <task-list>
$tasks = $task_list -> childNodes; // список дочерних узлов (<task>)
// Вывод документа XML
for ($i = 0; $i < $tasks -> length; $i++) // обход по узлам task
{
$output .= "
\n<table>\n";
$task = $tasks -> item($i); // узел task
// вывод срока сдачи deadline
$deadline = $task -> attributes -> getNamedItem("deadline") -> nodeValue; // строка 25
$output .= $deadline;
// вывод узла fio
$fio = $task -> getElementsByTagName("fio") -> item(1) -> nodeValue;
$output .= "<tr>\n
<td>ФИО</td><td>".$fio."</td>\n
</tr>\n";
$output .= "</table>";
}
}
}
function viewDoc($a)
{
global $output;
include 'unicode.inc';
if (!empty($a) && file_exists($a))
{
$dom = new domDocument ('1.0', Encoding);
$dom -> preserveWhiteSpace = false;
$dom -> load($a);
$task_list = $dom -> documentElement; // корневой элемент <task-list>
$tasks = $task_list -> childNodes; // список дочерних узлов (<task>)
// Вывод документа XML
for ($i = 0; $i < $tasks -> length; $i++) // обход по узлам task
{
$output .= "
\n<table>\n";
$task = $tasks -> item($i); // узел task
// вывод срока сдачи deadline
$deadline = $task -> attributes -> getNamedItem("deadline") -> nodeValue; // строка 25
$output .= $deadline;
// вывод узла fio
$fio = $task -> getElementsByTagName("fio") -> item(1) -> nodeValue;
$output .= "<tr>\n
<td>ФИО</td><td>".$fio."</td>\n
</tr>\n";
$output .= "</table>";
}
}
}
Решение:
заменить индекс в
Код:
$fio = $task -> getElementsByTagName("fio") -> item(1) -> nodeValue;