getElementsByTagName() -- Gets elements by tagname // nodeValue : The value of this node, depending on its type. // Load XML File. You can use loadXML if you wish to load XML data from a string $objDOM = new DOMDocument(); $objDOM->load("joe_non-us-nov.xml"); //make sure path is correct $h = fopen("joe_nonus_academic_november.csv", "w"); $note = $objDOM->getElementsByTagName("position"); // for each note tag, parse the document and get values for // tasks and details tag. foreach( $note as $value ) { //$locs = $value->getElementsByTagName("jp_sub_postal"); //$loc = $locs->item(0)->nodeValue; // Get the fields /* $fields = $value->getElementsByTageName("jc_description"); $all_fields = ""; foreach($fields as $ff) { $all_fields .= $ff } */ $cities = $value->getElementsByTagName("jp_sub_city"); $city = $cities->item(0)->nodeValue; $all_cities = array($city); //echo $cities->item(1)->nodeValue; // Might be missing if($city == "") { $locs = $value->getElementsByTagName("locations"); $location = $locs->item(0)->nodeValue; echo $location; } $states = $value->getElementsByTagName("jp_sub_state"); $state = $states->item(0)->nodeValue; $all_states = array($state); //$state = $states->item(0)->nodeValue; $countrys = $value->getElementsByTagName("country"); $country = $countrys->item(0)->nodeValue; $all_countries = array($country); $names = $value->getElementsByTagName("jp_institution"); $name = $names->item(0)->nodeValue; $urls = $value->getElementsByTagName("jp_inf_URL"); $url = $urls->item(0)->nodeValue; $dead = $value->getElementsByTagName("jp_submit_deadline"); $dead = $dead->item(0)->nodeValue; $titles = $value->getElementsByTagName("jp_title"); $title = $titles->item(0)->nodeValue; $adn = $value->getElementsByTagname("jp_joe_adnum"); $adnum = $adn->item(0)->nodeValue; // Loop through multiple locations $i = 0; if($city != "") { foreach($all_cities as $city) { // Create a new string for each location if($dead != "") $url = ''.str_replace(",", " ", $title).'
Deadline: '.str_replace(",", " ", $dead); else $url = ''.str_replace(",", " ", $title).''; $ss = '"'.$name.'","'.$title.'","'.$all_cities[$i].', '.$all_states[$i].' '.$all_countries[$i].'",'.$url; fwrite($h, $ss."\r\n"); $i++; } } else { if($dead != "") $url = ''.str_replace(",", " ", $title).'
Deadline: '.str_replace(",", " ", $dead); else $url = ''.str_replace(",", " ", $title).''; $ss = '"'.$name.'","'.$title.'","'.$location.'",'.$url; fwrite($h, $ss."\r\n"); } //$details = $value->getElementsByTagName("details"); //$detail = $details->item(0)->nodeValue; } fclose($h); ?>