Reputation: 381
I am working with uspto patent assignment api. I have just write a sample code to get the result. The result coming in xml format i parsed that xml and i want to display titles using foreach loop but showing only one value.
index.php
<?php
$data = file_get_contents('usptodata.xml');
$arr = simplexml_load_string($data);
foreach($arr->result as $values){
echo $values->doc->str[6];
}
?>
usptodata.xml
[result] => SimpleXMLElement Object
(
[doc] => Array
(
[0] => SimpleXMLElement Object
(
[str] => Array
(
[0] => 41196-840
[1] => 041196-0840
[2] => 41196
[3] => 840
[4] => N
[5] => 3
[6] => ASSIGNMENT OF ASSIGNORS INTEREST (SEE DOCUMENT FOR DETAILS).
[7] => Y
[8] => 0879-1385PUS2
[9] => BIRCH, STEWART, KOLASCH & BIRCH, LLP
[10] => 8110 GATEHOUSE ROAD, SUITE 100 EAST
[11] => FALLS CHURCH, VA 22042-1248
[12] => METHOD FOR INSERTING MEDICAL INSTRUMENT
[13] => en
[14] => 14046630
[15] => NULL
[16] => Paul CURCILLO
[17] => NULL
[18] => NULL
[19] => 20140100431
[20] => CURCILLO, PAUL
[21] => THE INSTITUTE FOR CANCER RESEARCH D/B/A FOX CHASE CANCER CENTER
)
)
[1] => SimpleXMLElement Object
(
[str] => Array
(
[0] => 41166-549
[1] => 041166-0549
[2] => 41166
[3] => 549
[4] => N
[5] => 2
[6] => CONFIRMATORY LICENSE (SEE DOCUMENT FOR DETAILS).
[7] => Y
[8] => MEMORIAL SLOAN KETTERING CANCER CENTER
[9] => 1275 YORK AVE, BOX 524
[10] => OFFICE OF TECHNOLOGY DEVELOPMENT
[11] => NEW YORK, NY 10065
[12] => KRAS MUTATIONS AND RESISTANCE TO ANTI-EGFR TREATMENT
[13] => en
[14] => 14790492
[15] => NULL
[16] => Federica Di Nicolantonio, David B. Solit, Alberto Bardelli, Salvatore Siena
[17] => NULL
[18] => NULL
[19] => 20160095920
[20] => SLOAN-KETTERING INSTITUTE FOR CANCER RESEARCH
[21] => NATIONAL INSTITUTES OF HEALTH - DIRECTOR DEITR
)
)
)
In output only single title is coming like this. "ASSIGNMENT OF ASSIGNORS INTEREST (SEE DOCUMENT FOR DETAILS).". How can i get all index[6] titles.
Upvotes: 0
Views: 21
Reputation: 54841
I suppose it should be:
$data = file_get_contents('usptodata.xml');
$arr = simplexml_load_string($data);
// proper variant
foreach($arr->result->doc as $cur_doc){
echo $cur_doc->str[6] . PHP_EOL;
}
Explanation: as you have result
object, which is a part of $arr
you need to iterate it's doc
property, so it is $arr->result->doc
.
In you initial case: $arr->result
means "iterate over all subitems of result
", but result
has only one subitem: doc
. So your foreach
takes just doc
without going deeper and iterating over doc
subitems.
Upvotes: 2