Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im trying to get the name atriburte of the type element in the following feed using xpath.

<response request="getHierarchyByMarketType" code="001" 
          message="success" debug="">    
<jonny>    
  <class id="5" name="Formula 1" maxRepDate="2012-12-19" maxRepTime="15:03:34">    
    <type id="4558" name="F1 Championship" lastUpdateDate="2012-11-26"
          lastUpdateTime="16:17:33">

to do this I'm using

$market_name = $wh_xml->xpath('/response/jonny/class/type/@name');

and then using

<h2>
  <?= $market_name ?>
</h2>

in my view, but instead of it returning my expected "F1 Championship" im getting a:

Array to string conversion

notice, but I'm not sure why, I thought xpath would return the value of @name as a string?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

EDIT: use list() to get just one value instead of an array:

list($market_name) = $wh_xml->xpath('//type/@name');
echo $market_name;

see it working: http://3v4l.org/rNdMo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...