oskars21 Posted May 10, 2012 Report Share Posted May 10, 2012 <wct:Seeds> <wct:Seed> <wct:SeedURL>http://www.jl-valmiera.lv/</wct:SeedURL> <wct:SeedType>Secondary</wct:SeedType> </wct:Seed> <wct:Seed> <wct:SeedURL>http://www.tagad.lv/</wct:SeedURL> <wct:SeedType>Secondary</wct:SeedType> </wct:Seed> <wct:Seed> <wct:SeedURL>http://www.jaunaislaiksjurmala.lv/</wct:SeedURL> <wct:SeedType>Secondary</wct:SeedType> </wct:Seed> <wct:Seed> <wct:SeedURL>http://www.jl.lv/</wct:SeedURL> <wct:SeedType>Primary</wct:SeedType> </wct:Seed> </wct:Seeds> xml fragmetns private function loadXmlData() { $xml_row = glob($this->dir_path . "*", GLOB_ONLYDIR); $this->data = array(); foreach ($xml_row as $FileNamePath) { $data_row = array(); $xml_str = file_get_contents($fileNameFullPath); $xml_str = preg_replace('~(</?|\s)([a-z0-9_]+):~is', '$1$2_', $xml_str); $xml_test_data = simplexml_load_string($xml_str); $xml_data = new SimpleXMLElement($xml_str); $data_row['url'] = (string) $xml_data->mets_dmdSec->mets_mdWrap->mets_xmlData->wct_wct->wct_Target->wct_Seeds->wct_Seed->wct_SeedURL; $data_row['type'] = (string) $xml_data->mets_dmdSec->mets_mdWrap->mets_xmlData->wct_wct->wct_Target->wct_Seeds->wct_Seed->wct_SeedType; $this->data[] = $data_row; } } scripta fragments un man vajag atlasīt pirmo urli ar type primary. kāds gudrāk prāts varētu man izpalidzēt kā to norealizēt? Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 10, 2012 Report Share Posted May 10, 2012 (edited) public function primary_url() { foreach($this->data){ if($type == 'primary'){ return $url; } } } Edited May 10, 2012 by xPtv45z Quote Link to comment Share on other sites More sharing options...
oskars21 Posted May 10, 2012 Author Report Share Posted May 10, 2012 nu labi vinsh noker to type primary bet, ka zinās ka vajag tieshi to urli, kas ir virs viņa? Quote Link to comment Share on other sites More sharing options...
indoom Posted May 10, 2012 Report Share Posted May 10, 2012 (edited) Varbūt kas šitāds $result = $xml_data->xpath("//wct_Seed[contains(wct_SeedType,'Primary')]"); $data_row['url'] = !empty($result[0]) ? (string)$result[0]->wct_SeedURL : ''; $data_row['type'] = 'Primary'; Edited May 10, 2012 by indoom Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 10, 2012 Report Share Posted May 10, 2012 (edited) Kāpēc pirms, tu jau rakstīji - "man vajag atlasīt pirmo urli ar type primary" Tev jau tur masīvā tiek salikti dati pa seediem, kam ir type un ir url parametri. Nav jau svarīgi vai xmlā, url atrodas pirms type vai pēc, kamēr viņi ir iekš viena seed. Varbūt šis tev kaut kādu apgaismību dos, kā ko dabūt, no masīva - var_dump($this->data) Edited May 10, 2012 by xPtv45z Quote Link to comment Share on other sites More sharing options...
oskars21 Posted May 10, 2012 Author Report Share Posted May 10, 2012 (edited) <wct:Seed> <wct:SeedURL>http://www.jaunaislaiksjurmala.lv/</wct:SeedURL> <wct:SeedType>Secondary</wct:SeedType> </wct:Seed> <wct:Seed> <wct:SeedURL>http://www.jl.lv/</wct:SeedURL> <----- vajag sho urli <wct:SeedType>Primary</wct:SeedType> </wct:Seed> bet tavs variants panem urli no secondary ša vai ta un tie type primary var but ari vairāki, tapēc vajag atlasit 1 ko atrod. Edited May 10, 2012 by oskars21 Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 10, 2012 Report Share Posted May 10, 2012 Parādi, ko izvada, $this->data, pēc loadXmlData izpildes. Quote Link to comment Share on other sites More sharing options...
oskars21 Posted May 14, 2012 Author Report Share Posted May 14, 2012 atrisināju savu sāpi ar, bet nu paldies par to pašu if (count($xml_data->mets_dmdSec->mets_mdWrap->mets_xmlData->wct_wct->wct_Target->wct_Seeds->wct_Seed) > 0) { foreach ($xml_data->mets_dmdSec->mets_mdWrap->mets_xmlData->wct_wct->wct_Target->wct_Seeds->wct_Seed as $node) { if($node->wct_SeedType=='Primary') $data_row['url']= $node->wct_SeedURL; } Quote Link to comment Share on other sites More sharing options...
indoom Posted May 14, 2012 Report Share Posted May 14, 2012 Kāpēc xpath nederēja? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.