Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 4 of 4
  1. #1
    DNF Regular
    stueynet's Avatar
    Join Date
    Feb 2004
    Location
    Toronto
    Posts
    733
    DNF$
    5,156
    Bank
    0
    Total DNF$
    5,156
    Donate  

    Parsing an xml object

    I am trying to parse an xml object. Each element in the object looks like this:

    Code:
    [entry] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [title] => Title of the thing
                        [link] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [rel] => alternate
                                        [type] => text/html
                                        [href] => http://www.thelinkurl.com
                                    )
    
                            )
    
    
                    )
    
               [1] => SimpleXMLElement Object
                    (
                        [title] => Title of the number 2 thing
                        [link] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [rel] => alternate
                                        [type] => text/html
                                        [href] => http://www.thelinkurlfornumber2.com
                                    )
    
                            )
    
    
                    )
    I am able to get the list of titles no problem but I do not know how to get the href attribute of the link node. Can someone help. Here is my php code which works:


    PHP Code:
    $obj simplexml_load_file($rss_source);
    foreach(
    $obj->entry as $child)
        {
        echo 
    "<li><a href='#'>".$child->title."</a></li>";
        
    print_r($link);
        } 
    What do I put in the # to get the @href attribute??

  2. #2
    Platinum Lifetime Member
    liberator's Avatar
    Join Date
    Jan 2007
    Location
    Canada
    Posts
    646
    Country

    Canada
    DNF$
    891
    Bank
    0
    Total DNF$
    891
    Donate  
    Have you tried: (haven't tested)

    PHP Code:
    $obj simplexml_load_file($rss_source);
    foreach(
    $obj->entry as $child)
        {
        echo 
    "<li><a href='".$child->link->attributes()->href."'>".$child->title."</a></li>";
        
    print_r($link);
        } 

    Canadian Registrar ~~ Ready.ca

  3. #3
    DNF Regular
    stueynet's Avatar
    Join Date
    Feb 2004
    Location
    Toronto
    Posts
    733
    DNF$
    5,156
    Bank
    0
    Total DNF$
    5,156
    Donate  
    Quote Originally Posted by liberator View Post
    Have you tried: (haven't tested)

    PHP Code:
    $obj simplexml_load_file($rss_source);
    foreach(
    $obj->entry as $child)
        {
        echo 
    "<li><a href='".$child->link->attributes()->href."'>".$child->title."</a></li>";
        
    print_r($link);
        } 


    Nice that worked!! Thank you so much.

  4. #4
    Platinum Lifetime Member
    liberator's Avatar
    Join Date
    Jan 2007
    Location
    Canada
    Posts
    646
    Country

    Canada
    DNF$
    891
    Bank
    0
    Total DNF$
    891
    Donate  
    No problem Stu!!
    Canadian Registrar ~~ Ready.ca

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Domain name forum recommended by Domaining.com