I would like to read files XML. Do you know how to do?![]()
I would like to read files XML. Do you know how to do?![]()
Read, or parse? Reading is done the same as any other file:There is an extension to PHP to parse XML, unless disabled at build time.PHP Code:
<?php
$xml = implode(file("myfile.xml"), "\n");
?>
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!
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.![]()
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).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?Eh?Actually I receive files ending HTML.
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!
I do not know any other possibility to sort such files by date.Or maybe...Originally Posted by Twey
Can you please explain me more?Originally Posted by Twey
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.
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.
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:The reason for incomplete URLs is for server reasons (mirrors, languages, countries, etc.)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.Warning: may cause your page to load like a pig.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).
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!
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)?Warning: may cause your page to load like a pig.
- Can you tell me if XML files can as extension HTML or allways XML? I'm new.Originally Posted by xerxes
- What do you mean by loop?
Is correct code for this:
- What to do if names of files are changing?PHP Code:
<?php
if (!$dom = domxml_open_file("example.xml")) {
echo "Error while parsing the document\n";
exit;
}
$root = $dom->document_element();
?>
-The XML file can have any extension.- Can you tell me if XML files can as extension HTML or allways XML? I'm new.
- What do you mean by loop?
-The loop is something like:
PHP Code:
for ($i = 0; $i < $items->length; $i++) {
echo $items->item($i)->nodeValue . "\n";
}
Close enough. I like the below for better parsing.Is correct code for this:
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();
Use the directory functions to look for the appropriate filename structure in a specified directory.- What to do if names of files are changing?
Bookmarks