Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Reading content in XML on server

  1. #1
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reading content in XML on server

    I would like to read files XML. Do you know how to do?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Read, or parse? Reading is done the same as any other file:
    PHP Code:
    <?php
      $xml 
    implode(file("myfile.xml"), "\n");
    ?>
    There is an extension to PHP to parse XML, unless disabled at build time.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks,
    it works showing and reading files on web site . Do you know if files have structure content, how to store files in table or there is usually procedure for such files that I can publish e.g. last 10 up-to-date?

    Actually I receive files ending HTML.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Do you know if files have structure content, how to store files in table or there is usually procedure for such files that I can publish e.g. last 10 up-to-date?
    I don't understand you. You want to store the files themselves in a table of some sort? This can be done using a binary field (LONGBLOB is a good choice if using MySQL).
    Actually I receive files ending HTML.
    Eh?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    You want to store the files themselves in a table of some sort?
    I do not know any other possibility to sort such files by date.Or maybe...

    Quote Originally Posted by Twey
    LONGBLOB is a good choice if using MySQL
    Can you please explain me more?

    I have files in HTML and its structure is defined. So, position of date, title of article and full contant is defined. The name of files is changing.

    I would like to publish just e.g. first 5 articles with
    link:
    Date
    Headline

    User will click on link and article will be shown in full content
    Last edited by toplisek; 03-15-2006 at 07:58 AM.

  6. #6
    Join Date
    Mar 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'd have to see the XML, but you could certainly use the DOM XML. It's usually built in to PHP4. In PHP5 the equivalent PHP4 DOM is a PECL package, so you just have to add the extension, although the DOM in PHP5 (that is built in) is better.
    Then just do a loop for each one of the items and dynamically create the table information (including the article, but the article will have a display:none). Then using JS DOM, make it so that when you click on the link it'll set display:block. If you don't like that, then do a popup window or goto another page (i.e. _self).

    PHP4 php.net page: manual/en/ref.domxml.php
    PHP5: manual/en/ref.dom.php

    The reason for incomplete URLs is for server reasons (mirrors, languages, countries, etc.)

    Other alternatives include SimpleXML (PHP5), XML Parser (expat include), and many others, including 'homemade' classes.
    Last edited by xerxes; 03-15-2006 at 11:15 PM.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The reason for incomplete URLs is for server reasons (mirrors, languages, countries, etc.)
    If you link to the URL on www.php.net it'll select and redirect to a mirror of its choosing. Also, it should be noted:
    Requirements

    This extension makes use of the GNOME XML library. Download and install this library. You will need at least libxml-2.4.14. To use DOM XSLT features you can use the libxslt library and EXSLT enhancements from http://www.exslt.org/. Download and install these libraries if you plan to use (enhanced) XSLT features. You will need at least libxslt-1.0.18.
    Then just do a loop for each one of the items and dynamically create the table information (including the article, but the article will have a display:none).
    Warning: may cause your page to load like a pig.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Warning: may cause your page to load like a pig.
    Ok, I know that I do not know everything, so how would you go about this? I know that if you have an immense amount of data, it'll load like a pig. But how would you go about it? Load just the headers? Or use something like AJAX and constantly load on more data (which would kill the connection end, or at the least take it down to a crawl)?

  9. #9
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by xerxes
    Then just do a loop for each one of the items
    - Can you tell me if XML files can as extension HTML or allways XML? I'm new.
    - What do you mean by loop?

    Is correct code for this:
    PHP Code:
    <?php

    if (!$dom domxml_open_file("example.xml")) {
     echo 
    "Error while parsing the document\n";
     exit;
    }

    $root $dom->document_element();
    ?>
    - What to do if names of files are changing?

  10. #10
    Join Date
    Mar 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    - Can you tell me if XML files can as extension HTML or allways XML? I'm new.
    - What do you mean by loop?
    -The XML file can have any extension.
    -The loop is something like:
    PHP Code:
    for ($i 0$i $items->length$i++) {
    echo 
    $items->item($i)->nodeValue "\n";

    Is correct code for this:
    Close enough. I like the below for better parsing.
    PHP Code:
    if (!$dom domxml_open_file("suggestions.xml",DOMXML_LOAD_PARSING +//0
                
    DOMXML_LOAD_COMPLETE_ATTRS //8
                
    DOMXML_LOAD_SUBSTITUTE_ENTITIES //4
                
    DOMXML_LOAD_DONT_KEEP_BLANKS //16
                
    )) {
                echo 
    "Error while parsing the document\n";
                exit;
            }
            
    $doc $dom->document_element(); 
    - What to do if names of files are changing?
    Use the directory functions to look for the appropriate filename structure in a specified directory.

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
  •