php and xml<

liunx

Guest
Hi, I'm tring out xml, and I found some functions in PHP that belongs to xml. But I cant figure out how to use them.
I'm thinking of making a guestbook or something, where the stuff is stored in a xml file. I managed to show the xml file with some javascript. But how can I write stuff to the file? Can I use some of the xml functions in php? And how can I show the xml file with php?

By the way, I have a xsl file too, which the javascript uses to show the xml file. Can I do that too with php?I've never worked with the xml functions but I'd assume you could open up the xml file and append a new entry to the bottom or something. Just would have to chmod the right permissions and such.

Someone else can answer better, I'm guessing. :)
Just saying what I know, or at least think I know. ;)didn't help me much, no. But thanks anyway :) anyone else that know more?http://www.devshed.com has some good articles on using XML and PHP. i would find the articles for you, but it seems it is down at this momentI have never used it either and I don't plan on it. but did you read the example in the manual? seems to me that it opens a xml file and displays it.

<?php
$file = "data.xml";
$depth = array();

function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
print "$name\n";
$depth[$parser]++;
}

function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>Hmm, xml is bleeding-edge technology.

Currently, too, it is a solution looking for a problem to solve.Originally posted by giz
Hmm, xml is bleeding-edge technology.

Currently, too, it is a solution looking for a problem to solve.

Hehe. Everything is going XML these days. It will soon be hard to program anything useful, without knowing XML. If you would go deeper into programming, I bet you would see thousands of problems that XML has solved. And bleeding-edge? It's been around for a while.
Oh, and XHTML is XML ;)Originally posted by Rydberg
Oh, and XHTML is XML ;)
not quite, it is derived from it but it is more closer to html than xml. you can't control as much as XML can, and you can't create you own tags in xhtml, the main purpose of xml and the ability to describe the information instead of displaying it.

XML tags are not predefined in XML. You must define your own tags. in xhtml you can't.It's an XML application. Just because I can't define my own tags, doesn't mean it's not XML. The tags are just predefined, like in many other XML applications. Of course they are taken from HTML, for familiarity.
It's useful to be able to define your own tags when you need to use XML with your own program, maybe for a configuration file or such.
You don't define your own tags when you write XML for an interpreter that is programmed to only understand a few specific tags. A browser interpreting XHTML would be an example of that. This is the way most XML enabled applications work.
What is the correct way to start an XHTML document? Something like:
<?xml version="1.0" encoding="UTF-8"?>
You'll have a hard time proving this isn't XML :)I never start my xhtml like that becuase it bugs the browsers out, especially IE.yeah, most people dont, but it is the way you are SUPPOSED to start xhtml documents if it is to be truly 100% valid xhtml. they just dont put that in the validator because it makes browsers wig outI am not saying it isn't like xml, I am just saying you can't say it is xml. if it was xml than it wouldn't be xhtml would it?

it may be close to xml since it was derived from it, but it is not xml. sop what if you use a similiar doctype, doesn't make it xml. xml purpose is to create your own tags for describing your data, not displaying it like html as xhtml does.

The Extensible HyperText Markup Language (XHTML? is a family of current and future document types and modules that reproduce, subset, and extend HTML, reformulated in XML. XHTML Family document types are all XML-based, and ultimately are designed to work in conjunction with XML-based user agents
doesn't make it xml. key word, XML-based and extend HTML

doctypes don't make it xml.>> ... reformulated in XML <<Whatever, scoutt ;)

XHTML is written in XML, just like this text is written in English. XSD is written in XML. XSLT is written in XML. MathML is written in XML. Need I go on? I would say these words are English, so why wouldn't XHTML be XML?
You can add your own tags to an XHTML document, but it will then no longer be valid XHTML, and then just become a well-formed XML document. Valid XHTML documents are valid XML documents.
DOCTYPE? I didn't say anything about DOCTYPE's. What I pasted, was an XML declaration.
XML's purpose isn't necessarily for you - the user - to be able to create your own tags.
Quote W3C all you want, but I suggest you learn more about XML before you get into a discussion like this.


On topic; Tussi, I haven't yet used much of the XML functions, yet, but I have messed a bit with Sablotron and the XSLT functions. XML support has completely changed(and improved) in PHP5, so you might wanna check that out.Originally posted by Rydberg
You can add your own tags to an XHTML document, but it will then no longer be valid XHTML, and then just become a well-formed XML document. Valid XHTML documents are valid XML documents.
DOCTYPE? I didn't say anything about DOCTYPE's. What I pasted, was an XML declaration.
XML's purpose isn't necessarily for you - the user - to be able to create your own tags.
Quote W3C all you want,
not everything I quoted was from w3. granted I do need to learn xml before I get myself in trouble, but from what I have read the only similarities is the declaration. xhtml looks and acts just like html, that is why I say it isn't xml. xml doesn't look or act like html.
Originally posted by Rydberg
but I suggest you learn more about XML before you get into a discussion like this.
I have open mouth and insert foot syndrom :POriginally posted by scoutt
xhtml looks and acts just like html, that is why I say it isn't xml. xml doesn't look or act like html.

Yes, XHTML looks much like HTML, and consists of pretty much the same tags, but it looks and behaves exactly like XML!
Compare:

<dining-room>
<furniture>
<table>
<chair material="plastic" />
<chair material="clay" />
<table>
<furniture>
</dining-room>



<html>
<body>
<table>
<tr><td>Data</td></tr>
<tr><td>Data</td></tr>
</table>
<body>
</html>

Not a super example, but it gets the point across, I hope. The names of the elements are different(or the same, as with "table"), but essentially, the documents "look" the same.
:)
 
Back
Top