Advanced Search

Results 1 to 3 of 3

Thread: Parsing XML data with PHP

  1. #1
    Join Date
    Aug 2005
    Location
    Youngstown Ohio
    Posts
    114
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Parsing XML data with PHP

    One last favor and Ill cubby back into my cavern of newly acquired server-side books.

    I am attempting to convert the following HTML into an XML file to be parsed onto the page with PHP so that it still displays as I originally designed it in HTML

    Code:
    <blockquote>
    <h3>Shadow: The Hidden Aspects of Self by Kelly Sosan Bearer</h3>
    One of the great discoveries of modern Western psychology is the fact that human beings have the potential to disown, repress and dissociate aspects of their own being and project those aspects onto others or out into the world. The shadow, also known as the disowned self, is the playground where our hidden aspects dwell...
    <div align="right"><a href="http://www.integralbuddha.net/topic_psychology_sthaos.htm" target="_top" class="button"><span>Continue reading...</span></a></div>
    </blockquote>
    <br>
    
    <blockquote>
    <h3>Stumbling on Happiness by Daniel Gilbert</h3>
    Are we just too stupid to be happy? Psychologist Daniel Gilbert reveals some of the common mental mistakes that defeat our search for happiness...
    <div align="right"><a href="http://www.integralbuddha.net/topic_psychology_soh.htm" target="_top" class="button"><span>Continue reading...</span></a></div>
    </blockquote>
    <br>
    
    <blockquote>
    <h3>Process, structure & form: an evolutionary transpersonal psychology of consciousness by Allen Combs & Stanley Krippner <img src="images/pdficon_small.gif"></h3>
    In the spirit of William James, we present a process view of humn consciousness. Our approach, however, follows upon Charles Tart's original systems theory of states of consciousness, although it differs in its reliance on modern sciences of complexity, especially dynamical systems theory and its emphasis on process and evolution. We argue that consciousness experience is constructive in the sense that it is the result of ongoing self-organizing and self-creating (autopoietic) processes in the mind and body. These processes follow a broad developmental agenda already described by psychologists such as Jean Piaget...
    <div align="right"><a href="http://www.sourceintegralis.org/Process,%20Structure,%20and%20Form.pdf" target="_top" class="button"><span>Download PDF</span></a></div>
    </blockquote>
    I have recently bought a few books on XML, PHP, PERL, and AJAX and after several days I came up with the following script:

    XML
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
       <psychology>
          <article>
             <title>Shadow: The Hidden Aspects of Self</title>
             <author>Kelly Sosan Bearer</author>
             <description>One of the great discoveries of modern Western psychology is the fact that human beings have the potential to disown, repress and dissociate aspects of their own being and project those aspects onto others or out into the world. The shadow, also known as the disowned self, is the playground where our hidden aspects dwell...</description>
             <link>http://www.integralbuddha.net/topic_psychology_sthaos.htm</link>
          </article>
          <article>
             <title>Stumbling on Happiness</title>
             <author>Daniel Gilbert</author>
             <description>Are we just too stupid to be happy? Psychologist Daniel Gilbert reveals some of the common mental mistakes that defeat our search for happiness...</description>
             <link>http://www.integralbuddha.net/topic_psychology_soh.htm</link>
          </article>
          <article>
             <title>Process, structure &amp; form: an evolutionary transpersonal psychology of consciousness</title>
             <author>Allen Combs &amp; Stanley Krippner</author>
             <description>In the spirit of William James, we present a process view of humn consciousness. Our approach, however, follows upon Charles Tart's original systems theory of states of consciousness, although it differs in its reliance on modern sciences of complexity, especially dynamical systems theory and its emphasis on process and evolution. We argue that consciousness experience is constructive in the sense that it is the result of ongoing self-organizing and self-creating (autopoietic) processes in the mind and body. These processes follow a broad developmental agenda already described by psychologists such as Jean Piaget...</description>
             <link>http://www.sourceintegralis.org/Process,%20Structure,%20and%20Form.pdf</link>
          </article>
       </psychology>
    PHP
    Code:
    <?php
    if (!$myxml=simplexml_load_file('topic_psychologyindex.xml')){
    
            echo 'Error reading the XML file';
    
            }
    
            foreach($myxml as $article){
    
                    echo '<blockquote><h3> ' . $article->title . ' by ' . $article->author . '</h3>';      
                    echo '' . $article->description . '<br />';  
                    echo '' . $article->link . '</blockquote><br />';  
    
            }
    
    ?>
    You can see how its displaying so far at LINK. So far so good!

    The only problem I keep running into is how to put the XML variable link into an anchor tag in my PHP so that it can be clicked and the user goes to such and such page. I'am used to javascript coding so I though that if I did
    Code:
    echo '<a href="' . $article->link . '" class="button">Continue reading...</a>
    All would be well and good but alas, it returns a parsing error
    All I'am really doing is indexing articles so that it would save me TONS of time whenever i posted a new article all I would have to do is edit my XML file.

  2. #2
    Join Date
    Aug 2005
    Location
    Youngstown Ohio
    Posts
    114
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    PROBLEM SOLVED!

    Code:
    echo '<a href=','' . $article->link . '',' class=','button','>Continue reading...</a>';

  3. #3
    Join Date
    Aug 2005
    Location
    Youngstown Ohio
    Posts
    114
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Some of the articles are in PDF format, so how would I go about indicating this in my XML?

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
  •