I would like to read files XML. Do you know how to do?:)
Printable View
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");
?>
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).Quote:
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?Quote:
Actually I receive files ending HTML.
I do not know any other possibility to sort such files by date.Or maybe...Quote:
Originally Posted by Twey
Can you please explain me more?Quote:
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
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.
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:Quote:
The reason for incomplete URLs is for server reasons (mirrors, languages, countries, etc.)
Quote:
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.Quote:
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).
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)?Quote:
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.Quote:
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.Quote:
- 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.Quote:
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.Quote:
- What to do if names of files are changing?
Any file can have any extension. Extensions are only a convention to make the contents of the file more easily guessable at a glance, and don't have any bearing on the actual content of the file.Quote:
- Can you tell me if XML files can as extension HTML or allways XML? I'm new.
What will do actually this code?Quote:
Originally Posted by xerxes
Can you tell specific function to use directory function? Need help...:)Quote:
Originally Posted by xerxes
Absolutely nothing, as the variable "items" isn't defined. It's an example of code that loops through all the elements inside a given element (or is that an array of elements? I don't know much about the PHP implementation of XMLDOM) and echoes the values of all tags inside it.Quote:
What will do actually this code?
Thank you for the start,:)