0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

What if foreach($arr->result->doc as $cur_doc)?
Thank you so much now it works can you tell me what mistake i did.
Updated with a little explanation.
your answer solved another problems also.Once again thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.