Jump to content
php.lv forumi

php un xml


oskars21

Recommended Posts

<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?

Link to comment
Share on other sites

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 by indoom
Link to comment
Share on other sites

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 by xPtv45z
Link to comment
Share on other sites

<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 by oskars21
Link to comment
Share on other sites

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;

  }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...