Ciao a tutti,
Vi riporto un frammento del file xml che voglio interrogare con Xpath:

<?xml version="1.0" encoding="UTF-8"?>
<WebSite
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.dia.uniroma3.it/~volpi/files/database"
xsi:schemaLocation="http://www.dia.uniroma3.it/~volpi/files/database
/afs/vn.uniroma3.it/user/v/volpi/public/public_html/files/database/database.xsd">

<ResearchGroup picture="http://www.dia.uniroma3.it/~compunet/images/compunet_banner.gif">
<NameGroup>Computer Networks Research Group</NameGroup>
<Description>computer networks</Description>
<Faculty>www.dia.uniroma3.it</Faculty>
<Department>www.web.dia.uniroma3.it</Department>
<University>www.uniroma3.it</University>
<CurrentMember>238651</CurrentMember>
<CurrentMember>238652</CurrentMember>
<CurrentMember>000001</CurrentMember>
<PastMember>238650</PastMember>
<PastMember>000002</PastMember>
<Project>netkit</Project>
<Project>hermes</Project>
<Coordinator>1</Coordinator>

<Publication>about netkit</Publication>
<Publication>Visualization of the Autonomous Systems Interconnections with HERMES</Publication>

<Publication>IPv6-in-IPv4 tunnel discovery: methods and experimental results</Publication>
<Publication>bgplay</Publication>

<Publication>Algorithms for the Inference of the Commercial Relationships between Autonomous Systems: Results Analysis and Model Validation</Publication>
</ResearchGroup>

<ResearchGroup picture="http://www.inf.uniroma3.it/research/GD.html">
<NameGroup>Graph Drawing</NameGroup>
<Description>
Algorithm Engineering Research Group
</Description>
<Faculty>http://www.dia.uniroma3.it/research/ACG.html</Faculty>
<Department>http://www.web.dia.uniroma3.it/</Department>
<University>http://www.uniroma3.it</University>
<CurrentMember>1</CurrentMember>
<Project>netkit</Project>
</ResearchGroup>
Con questo script estrapolo le informazioni:

Codice PHP:

<?php
    $real_path 
realpath("./files/database/database.xml");
    if(!
$domdb domxml_open_file($real_path)){
      die(
"Error while parsing the document");
      }
    else {
        echo 
"<CENTER><H3>Xpath Test execute.</H3></CENTER>";
    }
    
$xpath $domdb->xpath_new_context();
    
xpath_register_ns($xpath'my',"http://www.dia.uniroma3.it/~volpi/files/database");
?>    

<?php
  $query 
"/my:WebSite/my:ResearchGroup/my:NameGroup/text()";
  
$xpath_nodeset $xpath->xpath_eval($query);
  
$names = array();
  foreach (
$xpath_nodeset->nodeset as $iterator) {
   echo 
$names[] = $iterator->get_content()."
"
;
}
?>
ragazzi volevo chiedere:
1. ma come faccio a estrapolare soltanto il primo elemento senza usare il foreach??
Mi spiego meglio, con il foreach mi stampa:
"Computer Networks Research Group"
"Graphic Drawing"
Ma se voglio soltanto il primo???
non ditemi con l'indice dell'array perchè così ogni volta devo sapere con certezza la posizione dell'elemento.

Aspetto consigli...Vi ringrazio anticipatamente.
Saluti Simone V.