#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    20
    Rep Power
    0

    formatting xml using css


    Hi,

    I am very new to xml and am trying to format a document using css and add images to php file.

    here is the code :

    db.php :

    Code:
    <HTML>
    <HEAD>
    <style type=”text/css”>
    
    
    .ex {
        color: #ccc;
    }
    
    
    
    </style>
      </HEAD>
      <BODY>
    <?php
    
    $books = simplexml_load_file('5_book.xml');
    
    foreach ($books->book as $item){
    			echo "<div class=\"ex\">{$item->title}</div> was written by {$item->author} picture is {$item->picture}<br>";
    								}
    ?>
    </BODY>
    </HTML>
    The style sheet does nothing to {$item->title}, how do I change the colour of the text and add the images from 5_book.xml to {$item->picture}?

    and here is 5_book.xml :

    Code:
    <books>
    <book>
    <title>The Grapes of wrath</title>
    
    <author>John Steinbeck</author>
    <picture location="butterfly.gif" href="http://www.itv.com" border = "0" alt ="This is my picture"/>
    <website href = "http://www.codeunique.com/" text = "Codeunique"/>
    </book>
    
    <book>
    <title>The Pearl</title>
    <author>John Steinbeck</author>
    <picture location="bobcat.jpg" href="http://www.itv.com" border = "0" alt ="This is my picture"/>
    <website href = "http://www.codeunique.com/" text = "Codeunique"/>
    </book>
    </books>
    Any help would be greatly appreciated, thank you!.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    You're not styling XML. You're styling HTML. Like normal.

    Are there actually smart quotes in the <style> you have? They need to be normal quotes.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    20
    Rep Power
    0
    Hi Requinix,

    Thanks for the reply, have now got the css aspect working, what about the image?
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    $item->picture is the <picture> in the XML. You can get attributes from it using array syntax, like $item->picture["location"]. Insert those values into whatever kind of <img> you need.

    I guess the full path to the image is href + "/" + location? Or maybe it's just your example XML.

    Comments on this post

    • Will-O-The-Wisp agrees : Thanks for your help here and throughout the forums, Requinix. Also, nice new avatar!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    20
    Rep Power
    0
    Hi Requinix,

    Thanks very much for your help, but i'm still a little confused, I have tried to display an image from 5_book.xml using :

    picture is {$item->picture["5_book.xml"]}
    But nothing is displayed except for "picture is", I dont mean to be a pain but how do I display the image.

    Thanks for your time!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    20
    Rep Power
    0
    Hi Requinix,

    As you suggested I tried

    picture is {$item->picture["location"]}
    and I get back :

    picture is butterfly.gif
    Rather than the actual image, where am I going wrong?

    Thanks for your time!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    20
    Rep Power
    0
    Hi Requinix,

    Thanks very much for your posts!, problem solved!

IMN logo majestic logo threadwatch logo seochat tools logo