xml attributes and xml element count
Posted: Mon May 26, 2008 3:53 am
Hi Friends
i have this xml file
1.I want to know how can i return "8" the id of the latest node in order to add a new element?
2.how can i find out how many elements in the services node do i have
this code only returns the first node
thanks for your help
i have this xml file
Code: Select all
<?xml version="1.0"?>
<services>
<service id="1">
<title>????? ???? ?? ?????</title>
<language>fa</language>
<description></description>
</service>
<service id="2">
<title>????? ???????? ??</title>
<language>fa</language>
<description></description>
</service>
<service id="3">
<title>????? ???????? ?????? ?????</title>
<language>fa</language>
<description></description>
</service>
<service id="4">
<title>?????? ??????</title>
<language>fa</language>
<description></description>
</service>
<service id="5">
<title>Google Services in Iran parsitech</title>
<language>en</language>
<description></description>
</service>
<service id="6">
<title>Web Development Department of parsitech</title>
<language>en</language>
<description></description>
</service>
<service id="7">
<title>Programming Department of parsitech</title>
<language>en</language>
<description></description>
</service>
<service id="8">
<title>e-learning Components in parsitech</title>
<language>en</language>
<description></description>
</service>
</services>
2.how can i find out how many elements in the services node do i have
Code: Select all
public function retInfo()
{
if($this->__xmlFileName_str == "") return false;
$xpath = new DomXPath($this->__domContent_xml);
$this->title = $xpath->query('/services/service/title')->item(0)->nodeValue; // selecting the title via xpath
$this->language = $xpath->query('/services/service/language')->item(0)->nodeValue;
$this->description = $xpath->query('/services/service/description')->item(0)->nodeValue;
//echo($this->title);
return true;
} // retInfo()
thanks for your help