DomNode->attributes() problem
[email protected] (jux) Sat, 19 Jun 2004 13:36:53 +0300
| Newsgroups | php.xml.dev |
|---|---|
| Message-ID | <[email protected]> |
Hi
I wan't to get attribute values for a tags "<kaup>". I used functions:
DomNode->attributes()
DomElement->get_attribute("nr")
and they both worked, but it gives me an error for using those functions:
Fatal error: Call to a member function on a non-object in ... line of
funct...
Tell me what to have to do to get rid of that error.
xml file "tooted.xml":
<?xml version="1.0" encoding="ISO-8859-1"?>
<tooted>
<kaup nr="1">
<mudel>SH07ZPGA</mudel>
<firma>samsung</firma>
</kaup>
<kaup nr="2">
<mudel>ACH1800E</mudel>
<firma>samsung</firma>
</kaup>
</tooted>
here is php code:
<?php
class Toode{
function Toode(){
$dom = domxml_open_file("tooted.xml");
$root = $dom->document_element();
$kaubad=$root->get_elements_by_tagname("kaup");
for($i=0; i<count($kaubad); $i++){
$k=$kaubad[$i];
$nr=$k->attributes();
echo "kauba id: ".$nr[0]->value()."<br>";
}
}
}
$test=new Toode();
?>
and with get_attributes("nr"):
<?php
class Toode{
function Toode(){
$dom = domxml_open_file("tooted.xml");
$root = $dom->document_element();
$kaubad=$root->get_elements_by_tagname("kaup");
for($i=0; i<count($kaubad); $i++){
$k=$kaubad[$i];
$nr=$k->get_attribute("nr");
echo "kauba id: ".$nr."<br>";
}
}
}
$test=new Toode();
?>