Z33M@N Posted June 7, 2010 Share Posted June 7, 2010 The XML : <LEVEL style-name="Normal Level" style-name-escaped="Normal-Level" style-id="0-0-0-0" level-depth="0" toc-section="false"> <RECORD id="0-0-0-11" number="11" version="94"> <PARA style-name="pCenter-8" style-name-escaped="pCenter-8" style-id="0-0-0-53"> <PICTURE id="0-0-0-25173-img" object-class="folio objects" name="SAE_Forward_09.jpg" href="#!-- #EXECUTIVE:HOME_PATH --#/img/SAE_Forward_09.jpg" width="6870" height="810" left-border-line-color="0" left-border-line-width="0" left-border-space="0" right-border-line-color="0" right-border-line-width="0" right-border-space="0" top-border-line-color="0" top-border-line-width="0" top-border-space="0" bottom-border-line-color="0" bottom-border-line-width="0" bottom-border-space="0"/> </PARA> </RECORD> <RECORD id="0-0-0-12" number="12" version="3"> <PARA> </PARA> </RECORD> <RECORD id="0-0-0-16" number="13" version="84"> <PARA>Test data.</PARA> </RECORD> <RECORD id="0-0-0-250329" number="14" version="84"> <PARA>Test Data</PARA> </RECORD> <RECORD id="0-0-0-250330" number="15" version="84"> <PARA>Test Data</PARA> </RECORD> <RECORD id="0-0-0-250331" number="16" version="84"> <PARA>test.</PARA> </RECORD> <RECORD id="0-0-0-250332" number="17" version="84"> <PARA>test</PARA> </RECORD> </LEVEL> What I want to do is get the the RECORD TAGS and the PICTURE TAGS attribute "href", my code : $doc = new DOMDocument(); $doc->load( 'xml/english/0-0-0-10.xml' ); //get xml data and display it, then store in to mysql table. //$rows = $doc->getElementsByTagName( "ROW" ); $rows = $doc->getElementsByTagName( "RECORD" ); foreach( $rows as $row ) { $links = $row->getElementsByTagName( "PARA" ); $link = $links->item(0)->nodeValue; $picture = $row->getElementsByTagName( "PICTURE" ); $pict = $picture->get_attribute('href'); echo "<p>$link</p><p>$pict</p>"; } I'm getting the following error Call to undefined method DOMNodeList::get_attribute() . What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/204080-trying-to-get-multiple-xml-tags-to-display/ Share on other sites More sharing options...
ignace Posted June 7, 2010 Share Posted June 7, 2010 The correct method name is getAttribute() Quote Link to comment https://forums.phpfreaks.com/topic/204080-trying-to-get-multiple-xml-tags-to-display/#findComment-1068937 Share on other sites More sharing options...
Z33M@N Posted June 7, 2010 Author Share Posted June 7, 2010 The correct method name is getAttribute() thanks, but I'm still getting the error Call to undefined method DOMNodeList::getAttribute() Quote Link to comment https://forums.phpfreaks.com/topic/204080-trying-to-get-multiple-xml-tags-to-display/#findComment-1068943 Share on other sites More sharing options...
ignace Posted June 7, 2010 Share Posted June 7, 2010 $picture->item(0)->getAttribute(..) Quote Link to comment https://forums.phpfreaks.com/topic/204080-trying-to-get-multiple-xml-tags-to-display/#findComment-1068945 Share on other sites More sharing options...
Z33M@N Posted June 7, 2010 Author Share Posted June 7, 2010 $picture->item(0)->getAttribute(..) This is my code: $picture = $row->getElementsByTagName( "PICTURE" ); $picture->item(0)->getAttribute('href'); I'm still getting that error -> Fatal error: Call to a member function getAttribute() on a non-object in.... Could it be because I'm using a local server for testing? Quote Link to comment https://forums.phpfreaks.com/topic/204080-trying-to-get-multiple-xml-tags-to-display/#findComment-1068950 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.