php writting xml to web space

L

LazyJim

Guest
I want to experiment!

i want to make PHP files add and edit small xml files in my web space, (also going to use MySQL to record locations of the files).

And i need to know about server side xml parsing and applying xsl transitions so i can send the xml files out to HTML only clients?

anyone forsee any failures/problems?
any ideas or help?
encouragement even?
 
J

Jonty

Guest
Hi LazyJim

Well, where to begin? I believe what you describe is more than possible, providing the files and folders have the correct CHMOD permissions set. BarrysWorld runs PHP in safe-mode for security reasons, so there may be some issues surrounding the creation of new files, but certainly no problems with editing existing ones (that's just off the top of my head, I'll research the point more if you want).

At the moment, parsing XML files with PHP on the server side is a nightmare. It can be done, but the code involved is just daft, as you effectively have to write your own parser. I'll dig up a nice link to an XML parser written in PHP, if you would like? It ends up being around 5kb in size once written, which isn't too bad. In PHP5, which has just turned beta, things will hopefully improve due to a new XML library, but the code involved still won't be as simple as one would like.

As for XSL transitions, think of XSL as CSS for XML. Sadly, only fairly modern browsers support XML and XSL well enough to be any use (XSL is really only used to beautify raw XML documents, i.e. to make them more readable). Before we can really advise you we need to know what you plan to do with your XML?

Well, not very helpful, but reply detailing what specifics topics you'd like help on (e.g. PHP XML parsers, XSL etc) and I'll try and find some links for you :D

Kind Regards and Good Luck!

Jonty

P.S. You could always cut out the use of MySQL for indexing your XML files, and use an XML file for that role, e.g.

Code:
<xmlIndexFile>
  <file created="somedate" location="somepath/somefile.xml" title="Test XML File" />
</xmlIndexFile>

[i]. . . or, since parsing attributes can be difficult . . .[/i] 

<xmlIndexFile>
  <file>
    <created>somedate</created>
    <location>somepath/somefile.xml</location>
    <title>Test XML File</title>
  </file>
</xmlIndexFile>
 
L

LazyJim

Guest
well I thought maybe the db would be faster if the amount of data to manage got large, (I don't think u can access a xml structure without loading the whole file?)
But I may jsut concentrate on a non-db aproach.

I know xsl doesn't have much suport yet, that's why i asked about the server side xml parser and hopefully could use it to apply the xsl to the xml, giving html and sending that to the client.

I am basically using xml for the sake of using xml! Just for the experience and learning.

As a learning excersise, i think i may make an email manager or something, a bit like outlook express, but only for creating (and maybe sending) emails. Perhaps it might come in handy in the following senario as an example: at work, replying to an important email, work ends, must get bus can't be late so much house work to do at home, click save on the email writing web page, log back in at home later to finish and send it.

Or maybe a diary type thing, or even just an online notebook, I don't really know, it's hard to think of things that would benefit from xml instead of a db like MySQL.

Or for a more complicated one: a forum written in xml and xsl, storing the threads in xml, and using MySQL for the large management task of user profiles, subscribed threads, new/hot posts, different rooms etc - things different for each user. The db managing each user's 'view' of the forum and the xml looking after the content.

I think xml would be well suited to forum posts, and could provide a more useful solution to forum type code - dissallowing HTML (security) and tiing in well with my development of a wysiwyg post writer (felexibility) to replace this text based one.



So if anyone could help me choose a direction, I could get started (in the small amount of free time i have).
 
L

LazyJim

Guest
I've been looking for a way to put 'HTML Islands' into xml douments, or someway of escaping all the html tags so that i can store html code in an xml document without the tags becoming xml nodes, AND display the HTML later without it showing up as plain text (showing the code text).

The idea is to locate html code blocks and insert them into a the html document tree on the page the client is currently viewing.
I don't know why, but i don't like framesets!
 
J

Jonty

Guest
Hi LazyJim

Well, I'll just go through and address each point as you raise them, if that's okay? With regards using XML over a database, you're certainly right that the more complicated things become, the more a MySQL database begins to shine. That said, whilst things are at a fairly simple level of complexity, XML may well suffice.

In terms of accessing XML documents, you're right that you have to read the whole document (if you were to stop part way through, the parser wouldn't like it). If we're being precise, the parser actually requests the XML file x bytes at a time. The default value used is 4096 bytes (4Kb), which means if we have, say, a 10Kb XML file, the parser requests the first 4Kb, then the next 4Kb, then the final 2Kb. You'd never really know it did it this way, it's merely done to keep the load on the Internet connection and the system down to a minimum.

As for XML and XSL, this takes a little explaining. Say you have an XML file, which you style with XSL. Modern browsers will see the XSL styled XML page you send them, but you won't ever actually be sending them HTML. If they view the source, they'll see the XML code. Older browsers will thus see the raw XML code, even though it's been styled with XSL before being sent. Where the PHP XML parser comes in is being able to extract the necessary information from the XML document. You can then output this information as HTML which appears the same on all browsers. When people then view the page source, they don't see the raw XML code, but the HTML code you've generated with the XML appearing as plain text inside the page (effectively they have no idea the content has come from an XML file). That's probably not explained very well, but it's an important concept to grasp (one which the links below probably explain far better than I have).

As for your intended uses, don't worry, I know what you mean. XML is a buzzword at the moment, and it's good to have some background with using it. Some of the applications you suggest would traditionally be all MySQL, as there would be no advantage in using XML too. But, since you're wanting hands-on XML experience, it's fair enough to what to divide things, perhaps leaving the complicated tasks for MySQL, and simple storage for XML.

As for putting HTML islands into XML documents, it can be done, but you'll need to use a PHP XML parser to make sure that the HTML doesn't output as raw code as you've suggested. Basically, you have to convert the < > of HTML tags to their HTML entity values. For example, '<' is '&lt;' as a HTML entity, and '>' is '&gt;' as a HTML entity. If we left the HTML tags as they were, the XML parser would not be able to distinguish between them and XML code. This way, the XML parser passes by the HTML entities as if they were plain text; e.g.

Code:
[i]The following would all be treated as XML code[/i]

<xml>
  <myHTMLCode>
    <div>[b]Hello[/b]</div>
  </myHTMLCode>
</xml>

[i]Whereas this next code would not . . .[/i]

<xml>
  <myHTMLCode>
    &lt;div&gt;&lt;strong&gt;Hello&lt;/strong&gt;&lt;/div&gt;
  </myHTMLCode>
</xml>
The only downside to this solution is that it makes extremely ugly code. You could, of course, tell the parser to ignore certain elements, which may well prove a far better solution (or vica versa, so the parser ignores all tags, except specific tags which appear only in your XML document structure).

Well, I'm not too sure how helpful the above is. Anyway, on to some people who do know what they're talking about!

Firstly, I recommend checking out W3School's excellent XML and XSL chapterss. These really are great introductions to both topics. When you're feeling brave, you may also want to check out the XML Chapter of the PHP Manual, although this isn't for the fainthearted! Sitepoint also have some great XML and PHP articles. Recently they posted an article about creating an XML content management system; not forgetting their general XML and XSL articles and their RSS PHP parser (although designed for parsing RSS, the princples are the same for parsing XML). Querying your favourite search engine should also bring up many more tutorials and guides concerning XML, XSL, PHP and more.

Kind Regards
 
L

LazyJim

Guest
Thanks very much again very helpfull and fast responce!

Ok I have decided to ignore my MySQL db for now, as that is all 'new' to me too.

I found the W3Schools EXCELLENT introductions to many web languages and more. I think I've learned more since I got home and started reading them (last week) than I have at university!
Incidently, does anyone here know if the W3Schools exams are well recognised/well known or are they ignored by employers?


Thanks for the other links too, they should keep my hunger at bay for a bit.

As for converting html < and > to their entity codes, well yes that is a good solution I hadn't thought of, but I like the sound of making it ignore certain elements better!!
 
J

Jonty

Guest
Hi LazyJim

I agree that W3Schools really are brilliant. With regards their certification programme, I honestly don't know much about it, but I don't believe it would be recognised by employers (W3Schools only recently introduced this exam system). That said, I'm sure it wouldn't count against you, as any kind of certification is usually beneficial, but whether I'd be willing to hand over my own money is another question.

Good luck with your coding :D
 

Users who are viewing this thread

Similar threads

S
Replies
6
Views
625
wyrd_fish
W
P
Replies
13
Views
1K
wyrd_fish
W
B
Replies
2
Views
1K
B
S
Replies
5
Views
734
L_Plates
L
S
Replies
2
Views
541
wyrd_fish
W
Top Bottom