#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,657
    Rep Power
    171

    Access an elements attribute in <![CDATA[ (SimpleXml)


    How is it possible to access the value for attribute src (src="http://l.yimg.com/a/i/us/we/52/29.gif") in this page.

    Red below:
    -------------------------------------------------------------


    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <channel>

    <title>Yahoo! Weather - City of Gold Coast, AU</title>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/City_of_Gold_Coast__AU/*http://weather.yahoo.com/forecast/ASXX0047_f.html</link>
    <description>Yahoo! Weather for City of Gold Coast, AU</description>
    <language>en-us</language>
    <lastBuildDate>Sat, 30 Mar 2013 8:29 pm ACST</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="City of Gold Coast" region="QLD" country="Australia"/>
    <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
    <yweather:wind chill="72" direction="300" speed="5" />
    <yweather:atmosphere humidity="73" visibility="6.21" pressure="29.97" rising="1" />
    <yweather:astronomy sunrise="6:52 am" sunset="6:45 pm"/>
    <image>
    <title>Yahoo! Weather</title>
    <width>142</width>
    <height>18</height>
    <link>http://weather.yahoo.com</link>
    <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
    </image>
    <item>
    <title>Conditions for City of Gold Coast, AU at 8:29 pm ACST</title>
    <geo:lat>-28</geo:lat>
    <geo:long>153.43</geo:long>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/City_of_Gold_Coast__AU/*http://weather.yahoo.com/forecast/ASXX0047_f.html</link>
    <pubDate>Sat, 30 Mar 2013 8:29 pm ACST</pubDate>
    <yweather:condition text="Cloudy" code="26" temp="72" date="Sat, 30 Mar 2013 8:29 pm ACST" />
    <description><![CDATA[
    <img src="http://l.yimg.com/a/i/us/we/52/26.gif"/><br />
    <b>Current Conditions:</b><br />
    Cloudy, 72 F<BR />
    <BR /><b>Forecast:</b><BR />
    Sat - Mostly Clear. High: 77 Low: 70<br />
    Sun - Isolated Thunderstorms. High: 78 Low: 71<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss/weather/City_of_Gold_Coast__AU/*http://weather.yahoo.com/forecast/ASXX0047_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
    (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
    ]]></description>
    <yweather:forecast day="Sat" date="30 Mar 2013" low="70" high="77" text="Mostly Clear" code="33" />
    <yweather:forecast day="Sun" date="31 Mar 2013" low="71" high="78" text="Isolated Thunderstorms" code="37" />
    <guid isPermaLink="false">ASXX0047_2013_03_31_7_00_ACST</guid>
    </item>
    </channel>
    </rss>

    <!-- api11.weather.sp2.yahoo.com Sat Mar 30 10:27:19 PST 2013 -->
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,452
    Rep Power
    594
    Use DOM and 'find'.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,657
    Rep Power
    171
    Originally Posted by gw1500se
    Use DOM and 'find'.
    Not possible with simplexml?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,053
    Rep Power
    9398
    SimpleXML will get you the contents of the CDATA. Put those into a DOMDocument, getElementsByTagName, and grab the attribute from there.

    Comments on this post

    • gw1500se agrees : I should have been more explicit like you.

IMN logo majestic logo threadwatch logo seochat tools logo