-1

I have this XML:

<JobReference> <Type>STANDARD</Type> <Title>N° ANCIEN DOSSIER</Title> <Reference/>

And am running this PHP code:

$xmljobreference = simplexml_load_string ($GetJobResult->JobReferences->JobReference->Title );    
$referenceanciendossier = $GetJobResult->JobReferences->xpath( "//JobReference[@Title ='N°  ANCIEN DOSSIER']/Reference" );

But I am getting this error:

Fatal error:call to undefined method stdClass::xpath() on line 190

If I run var_dump($GetJobResult) I get:

 public 'JobReferences' => 
    object(stdClass)[149]
      public 'JobReference' => 
        array (size=7)
          0 => 
            object(stdClass)[150]
              ...
          1 => 
            object(stdClass)[151]
              ...
          2 => 
            object(stdClass)[152]

             public 'JobSeq' => int 920179
IMSoP
  • 89,526
  • 13
  • 117
  • 169
test
  • 19
  • 5
  • Debug. Is $GetJobResult set? – Gustaf Gunér Jun 16 '15 at 11:57
  • well stdClass objects dont have methods... Probably you want to do something with `$xmljobreference` – Steve Jun 16 '15 at 11:59
  • @Gustaf i add var_dump($GetJobResult) it's Object – test Jun 16 '15 at 12:02
  • @test I provided an answer. Try that – Gustaf Gunér Jun 16 '15 at 12:11
  • @Gustaf i try but i have this error call to undefined stdclass::xpath() and i put comment under your answer – test Jun 16 '15 at 12:32
  • I've just edited your question because the formatting made it impossible to read, but I'm still not at all clear what your code is doing. What is the line with `$xmljobreference` trying to do? How does the invalid snippet of XML you've posted relate to the partial output of `var_dump`? Try putting together a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), to help both yourself and us understand the problem. – IMSoP Jun 16 '15 at 21:41

1 Answers1

0

Well, as your var_dump shows you, JobReferences is built up by a JobReference which itself is an array with 7 items.

So assuming that you want to run the xpath function on all the array items, you need to run a foreach loop. Something like this should work:

$array = $GetJobResult->JobReferences->JobReference;
$results = array();

foreach($array as $reference){
    array_push($results, $reference->xpath( "//JobReference[@Title ='N°  ANCIEN DOSSIER']/Reference" ));
}
var_dump($results);
Gustaf Gunér
  • 2,272
  • 4
  • 17
  • 23