Announcement

Collapse
No announcement yet.

Parsing CDATA from XML file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hi there flat_stanley,

    Try this CSS...

    Code:
    
    #icon img {
        width: 6em; /* adjust value to suit  */
        height: auto;
     }
    


    ~ the original bald headed old fart ~

    Comment


    • #17
      It is not working. What is the problem???

      Comment


      • #18
        Hi there flat_stanley,

        the reason is does not work is due to your inadequate coding skills.

        For some reason you have seen fit to insert a comma here....

        Code:
        
        <style media="screen">
        
        #icon table,
        #icon p  {
            display: none;
         },
         #icon img {
            width: 100em;
            height: auto;
         }
        </style> 
          
        ...which prevents the code that follows from being executed.


        ~ the original bald headed old fart ~

        Comment


        • #19
          I have tried creating both files in .php and phtml extensions. Could you provide me a link of yours for me to look at?

          Comment


          • #20
            Please have a look at http://megaexplorer.net/weathertest.php

            Comment


            • #21


              You still haven't removed the comma.


              ~ the original bald headed old fart ~

              Comment


              • #22

                #icon table, #icon p { display: none; } Why is there a comma after 'table'?

                Comment


                • #23
                  One more question: I find that the weather icon doesnt change automatically from the RSS XML of Hong Kong Observatory, unless I refresh the webpage. Shouldn't PHP/PHTML be dynamic?

                  Comment


                  • #24
                    Hi there flat_stanley,


                    Why is there a comma after 'table'?
                    It is there to separate the two selectors.

                    It saves extra coding, as without it the
                    code would have to be written like this...

                    Code:
                    
                    #icon table {
                        display: none;
                     }
                    
                    #icon p {
                        display: none;
                     }
                    
                    I find that the weather icon doesn't change automatically...
                    The temperature and humidity values don't change automatically either.

                    PHP is not dynamic client-side,but it can be dynamic server-side.

                    Refreshing is a call to the server which will then update the content.

                    Check out the attachment which has a complete updating of your page
                    including the removal of all the unwanted code except the icon and an
                    automatic page reload.

                    The reload has been initially set to one minute but can be adjusted to
                    suit in the external javascript file.

                    Attached Files


                    ~ the original bald headed old fart ~

                    Comment


                    • #25
                      Hi there flat_stanley,

                      If you are wondering why my code shows it as unusually cold it is because I inadvertently
                      gave you the weather for Chertsey, England instead of Hong Kong.

                      This is the link that I should have used...
                      Hong Kong Weather HTML
                      In the php you may also want to change this...

                      PHP Code:
                         $temp=$temp-273.15
                      ...to this...

                      PHP Code:
                         $temp=round($temp-273.15,0); 

                      Click image for larger version

Name:	hong-kong.jpg
Views:	1
Size:	16.6 KB
ID:	1443349

                      Last edited by coothead; 01-08-2017, 11:08 AM.


                      ~ the original bald headed old fart ~

                      Comment


                      • #26
                        Thanks loads. I think I am learning a lot. However, I just met a programmer who says it is hard but not impossible to get the data individually from the CDATA section. Do you think he is bluffing?

                        Comment


                        • #27
                          Hi there flat_stanley,

                          I got the weather icon individually from the CDATA section,
                          and that is all that you said you wanted.


                          ~ the original bald headed old fart ~

                          Comment


                          • #28
                            May I have the air temperature and relative humidity from the CDATA section individually as well? I've been googling and trying to hone my skills in PHP but to no avail...

                            Comment


                            • #29
                              Hi there flat_stanley,

                              May I have the air temperature and relative humidity
                              from the CDATA section individually as well?
                              No that is not at all possible.


                              The weather icon is in an "HTML img element" in the "CDATA section"
                              and is, therefore,easily grabbable.

                              The temperature and humidity on the other are just floating text,
                              and ungrabbable as you can plainly see here...

                              Code:
                                <![CDATA[
                                 <img src="http://rss.weather.gov.hk/img/pic60.png" style="vertical-align: middle;">       <p>At
                                6 a.m.
                                       at the Hong Kong Observatory :<br/>
                                Air temperature : 19 degrees Celsius<br/>
                                Relative Humidity : 85 per cent<br/>
                               
                              In a previous post #7, I suggested that you use this site...
                              http://openweathermap.org/
                              ...as it has extremely easy to work with XML.

                              So why on earth are you so reluctant to use it?

                              In post #24 I gave you the complete replacement code for your page...
                              http://megaexplorer.net/weathertest.php
                              ...which, to be honest, is a total wreck and needs to be trashed..

                              So why on earth are you so reluctant to use the clean and working
                              code that was provided?

                              I've been googling and trying to hone my skills in PHP but to no avail...
                              All the more reason to take the code that you have been given.

                              This thread has almost thirty posts and you are still messing around.
                              Last edited by coothead; 01-19-2017, 06:10 PM.


                              ~ the original bald headed old fart ~

                              Comment

                              Working...
                              X