This is a discussion on Re: [PHP] DOM - parse HTML document within the PHP General forums, part of the PHP Programming Forums category; Hello Satyam, Thanks for your answering... >> I don't really get it to work with that functions from &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello Satyam,
Thanks for your answering... >> I don't really get it to work with that functions from >> http://www.php.net/manual/en/ref.dom.php >> I try to get the content of <td> fields on an external html page, where >> I just know some ids of the rows. >> Example: >> ... >> <tr id = 'tr01'> >> <td>1</td><td>2</td><td>3</td><td>4</td> >> </tr> >> <tr id = 'tr02'> >> <td>1</td><td>2</td><td>3</td><td>4</td> >> </tr> >> <tr id = 'tr01'> >> <td>1</td><td>2</td><td>3</td><td>4</td> >> </tr> >><tr id = 'tr02'> >> <td>1</td><td>2</td><td>3</td><td>4</td> >> </tr> >> ... >> PS: Please note, that id is written more than once. So >> DomDocument->getElementById('tr01') returns only one element and not two >> or more... >> I can't find out how to grab the data in the td fields... I don't find >> examples to look at... :-( >> I'd be really glad if somebody could give me some advice or tutorial >> websites about that... > To start with, an ID should never be repeated. A name can be repeated, > an ID shouldn't. That is why there is a function to get an array of > elements with a certain name but there is none to get a list of elements > with the same ID simply because there shouldn't be any. Something > helpful in traversing the DOM is any tool that gives you a good view of > the tree structure. One such comes already in the Firefox browser. Unfortunately, I have no way to modify the source html page, it's on the web. By the way, because I found it strange to have more than one field with the same id, I looked on the famous selfhtml tutorial website http://de.selfhtml.org which says that unique id is only mandatory for css, but not for javascript actually. I was surprised... http://de.selfhtml.org/css/formate/z...ividualformate http://en.selfhtml.org/css/formate/z...ividualformate (english translation is a little different) LS -- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail |
|
|||
|
----- Original Message -----
From: "Leonidas Safran" <Elektrik@gmx.net> > > By the way, because I found it strange to have more than one field with > the same id, I looked on the famous selfhtml tutorial website > http://de.selfhtml.org which says that unique id is only mandatory for > css, but not for javascript actually. I was surprised... > http://de.selfhtml.org/css/formate/z...ividualformate > http://en.selfhtml.org/css/formate/z...ividualformate > (english translation is a little different) > > That is correct but it is not complete. Everything that relies on a unique id would fail, CSS amongst others(which is what this article covers), but not the only one. Basically there are two functions to get elements by id or name: getElementById and getElementsByName. Notice the first one returns a single element since there cannot be more than one, the second one returns a collection of elements, since duplicates are allowed. Thus, if you put an id in an element, it is because you want to reach it, but if the id is duplicated then you cannot reach it any longer. Satyam |