Results 1 to 5 of 5
-
10-12-2011, 09:24 PM #1Junior Guru Wannabe
- Join Date
- Sep 2002
- Location
- Bohol, Philippines
- Posts
- 72
Extracting data from XML file by PHP
hi everybody,
I have a problem reading this xml file that i assigned to $marc variable:
Code:<datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Nursing care plans.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Hospitals</subfield> <subfield code="x">Case management services.</subfield> </datafield> <datafield tag="541" ind1=" " ind2=" "> <subfield code="a">MegaTEXTS</subfield> <subfield code="c">purchased</subfield> <subfield code="d">9/30/11</subfield> </datafield> <datafield tag="906" ind1=" " ind2=" "> <subfield code="a">7</subfield> <subfield code="b">cbc</subfield> <subfield code="c">orignew</subfield> <subfield code="d">1</subfield> </datafield>
Code:$obj = new SimpleXMLElement($marc); foreach ($obj->datafield as $datafield) { if ($datafield['tag'] == '650') { $subject=$subject.$datafield->subfield."<br>"; } }
Thank you.
-
10-12-2011, 11:46 PM #2Disabled
- Join Date
- Apr 2005
- Location
- Cochin
- Posts
- 2,452
You should probably use XML parser class
http://php.net/manual/en/book.xml.php
-
10-13-2011, 12:31 AM #3Junior Guru Wannabe
- Join Date
- Sep 2002
- Location
- Bohol, Philippines
- Posts
- 72
thanks for the link.
but i think my problem is that i lack the looping inside every datafield. that i'm not able to get.
-
10-13-2011, 01:09 AM #4Disabled
- Join Date
- Apr 2005
- Location
- Cochin
- Posts
- 2,452
-
10-13-2011, 01:48 AM #5Junior Guru Wannabe
- Join Date
- Sep 2002
- Location
- Bohol, Philippines
- Posts
- 72
thank you very much for the links.i got the solution from what you provided.
here's my code:
Code:$obj = new SimpleXMLElement($marc); foreach ($obj->datafield as $datafield) { if ($datafield['tag'] == '541') { foreach ($datafield->subfield as $subfield) { if ($subfield['code'] == 'd') { $this->acquisition=$subfield; } } } }
Similar Threads
-
PHP, reading from an xml file
By Shib in forum Programming DiscussionReplies: 2Last Post: 06-21-2010, 03:03 PM -
[PHP] Extracting data between two characters - a lot harder than I thought!
By jonathanbull in forum Programming DiscussionReplies: 6Last Post: 11-19-2006, 02:02 AM -
Extracting MYSQL table/field data into a text file?
By UkWebsiteFan in forum Programming DiscussionReplies: 1Last Post: 11-09-2004, 03:34 AM -
Extracting data using PHP [Template Sys]
By nick[x1] in forum Programming DiscussionReplies: 6Last Post: 08-16-2004, 09:29 AM -
Extracting raw log file data
By brookie in forum Web HostingReplies: 0Last Post: 09-21-2001, 11:44 AM