Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Php 5 Dom

Php 5 Dom
Thread Tools
Chris O'Brien
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 18, 2004, 11:44 AM
 
OK, I suppose I'd be able to look this up somewhere else, but I may as well ask here

Does anyone know why I've been forced to using childNodes->item(number) instead of childNodes[number] as one would expect? Is this a bug in php 5RC3, or am I missing something? I can't imagine why the php team would stray from the standard in this way, so, hopefully, it is purely a mild oversight in this release...

Anyone know for sure?
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jun 18, 2004, 01:00 PM
 
The PHP DOM is a series of classes, not a language construct, so you have to work with the class structure. It builds a nested series of objects, and then you work with those objects, they are allowing you to work with the DOM, not implementing it.
     
Chris O'Brien  (op)
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 18, 2004, 01:14 PM
 
That doesn't answer the question. I realise that it's a nested series of objects I'm working on, I know what DOM stands for and how things work, so it's pretty explanatory.
However, in moving from php4's implementation of DOMXML, to PHP5's, they've (fantastically - it was pants before) adhered to the W3C's naming convention etc for most things, but have seemed to neglect the referencing convention of [num] as I mentioned in my first post. Now, in at least one tutorial (and another external reference) I've seen, childNodes[num] has been used. I was wondering why I couldn't get it to work, despite the fact it seems to be documented that I should be able to. It's quite annoying, since I use XML DOM parsing all the time in other languages, where it does work.
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jun 18, 2004, 09:29 PM
 
You do know that the DOM does not require anything about the syntax of the language used to access it, yes? And that is what you are talking about, syntax. The W3C says nothing about this... they don't even require that frameworks that expose the DOM use their names for the functions.

PHP already has a meaning for $variableName[reference] in its syntax... and it is not quite the same thing as in JavaScript. PHP has a different syntax than JavaScript. $variableName->function[] does not exist in PHP so far as I can tell... and making it work simply because it looks like JavaScript is not a good reason to break the language. PHP is not JavaScript (ECMA Script).

I am not sure where you are getting your documentation/how-to's... but I have not seen anything like that on the (sparse) documentation on php.net... and that is the official source.
     
Chris O'Brien  (op)
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 19, 2004, 06:32 AM
 
Ouch, just read my reply - that was quite rude. Apologies, I was drunk enough that I don't remember typing that.

Anyhoo, I can't actually find the article where it did reference the childNodes with the [] syntax, but when I do, I'll post it, just for reference. I didn't know that the W3C's syntax wasn't a requirement - I presumed it was and hence the move from get_elements_by_tagname (etc) in php4 to getElementsByTagName in php5...

So my original question is just a question of syntax. I understand that php uses ->item() for an object collection, and I never once hinted that php was the same as javascript... I was just wondering why they use the same naming conventions for methods that the W3C spec recommends but not referencing syntax. It isn't a problem (obviously) just a quick question as to why.

I suppose, thinking about it, my question would also encompass why they don't use the . notation instead of ->, and that would be silly.

Anyhoo - 'twas a bit of a dumb question, but I was thrown by an article I read which used [] in dealing with php (I'll have to find that...).

Edit:
Now I remember where I got the impression you can use childNodes[]. It was at this page. However, since it's not in English, I may have gotten the wrong end of the stick.
( Last edited by Black Book; Jun 19, 2004 at 07:02 AM. )
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Millennium
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Jun 19, 2004, 09:29 AM
 
Does PHP support operator overloading? If not, then there's your answer; by implementing it as a class, they ensured that they couldn't do the childNodes[number] method.

To be honest, I find that the DOM has little use outside of Web pages; the same is true for SAX. Use them to read your document in, of course, but then build your own API on top of that. As long as your API calls out only to the standard APIs (SAX or DOM), you retain the porrtability and interoperability advantages of those standards, but everything above that layer will be much easier to work with.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Chris O'Brien  (op)
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 24, 2004, 04:20 AM
 
Just found out that it's SimpleXML that uses childNodes[num] syntax rather than DOMXML...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Oisín
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status: Offline
Reply With Quote
Jun 24, 2004, 08:56 AM
 
Originally posted by Black Book:
Edit:
Now I remember where I got the impression you can use childNodes[]. It was at this page. However, since it's not in English, I may have gotten the wrong end of the stick.
Nope, you seem to have got it right enough, as far as I can tell (which, admittedly, isn't far - I believe I am what can be referred to as a PHP dummy; and a DOM dummy (a DOMmy?) as well)...

But any-old-how, he does use $node->childNodes[1]->nodeValue; etc. in that example, and it doesn't seem not to work for him (I mean, he wouldn't have published it if it didn't, would he?)
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:12 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,