pc-magas / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

contents() and/or wrapInner() seems to don't work #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. <php>$article_element->contents()->wrapInner('<p></p>');</php>
2.
3.

What is the expected output? What do you see instead?
It should wrap all the inner element returning by contents method. But
instead of that I get two error : <error>Warning: Invalid argument supplied
for foreach() in phpQuery.class.php on line 2492</error>

What version of the product are you using? On what operating system?
r198

Please provide any additional information below.
that's I really want to do is : <php>$article_element->contents('>
not:([nodeType=1])')->wrapInner('<p></p>')</php> but sure it don't work any
more

Original issue reported on code.google.com by nicolas....@gmail.com on 6 Oct 2008 at 2:59

GoogleCodeExporter commented 9 years ago
Getting other strange error...

Using this :
<php>$article_element->contents()->not('[nodeType=1]')->wrapInner('<p></p>');</p
hp>

I'll get this : <error>Fatal error: Call to undefined method 
DOMText::getAttribute()
in phpQuery.class.php on line 2177</error>

Original comment by nicolas....@gmail.com on 6 Oct 2008 at 3:13

GoogleCodeExporter commented 9 years ago
In r199 filter method skips text nodes (and other non-elements). Try it now.

Original comment by tobiasz....@gmail.com on 6 Oct 2008 at 3:25

GoogleCodeExporter commented 9 years ago
In think I've got some error cause of the issue 49.
But I still have an error so : "Warning: Invalid argument supplied for 
foreach() in
phpQuery.class.php on line 2501"

Original comment by nicolas....@gmail.com on 6 Oct 2008 at 3:32

GoogleCodeExporter commented 9 years ago
I've added condition to prevent foreach warning in r200. Can you check what was
selected before call to contents(), using dumpWhois() ?

Original comment by tobiasz....@gmail.com on 7 Oct 2008 at 10:09

GoogleCodeExporter commented 9 years ago
Doing that :

<php>
        $article_element->html('hors paragraphe<p>Test</p>hors paragraphe');
        foreach ($article_element->contents('not:([nodeType=1])') as $test)
        {
            echo "<!--\n"pQ($test)->html())."\n-->\n";
        }
</php>

I'll get that :

<screen>
<br />
Warning:  Invalid argument supplied for foreach() in
/x/phpQuery.class.php on line 2667<br />
<!--

-->
<!--
hors paragraphe

-->
<!--
Test

-->
<br />
Warning:  Invalid argument supplied for foreach() in
/x/phpQuery.class.php on line 2667<br />

<!--

-->
</screen>

NB : cf comment 13 of issue 49

Original comment by nicolas....@gmail.com on 12 Oct 2008 at 1:44

GoogleCodeExporter commented 9 years ago
It seems to be the "html()" method which make the error...

Original comment by nicolas....@gmail.com on 12 Oct 2008 at 1:45

GoogleCodeExporter commented 9 years ago
With this DOM in my doc
<dom>
<div id="myTest"><p>hors paragraphe</p><p>Test</p>hors paragraphe</div>
</dom>

In jquery using 
<js>$('#myTest').contents().not("[nodeType=1]").wrap("<p/>")</js>

change my DOM in :
<dom>
<div id="myTest"><p>hors paragraphe</p><p>Test</p><p>hors paragraphe</p></div>
</dom>

Can't reproduce it in phpQuery :(.

Original comment by nicolas....@gmail.com on 12 Oct 2008 at 2:17

GoogleCodeExporter commented 9 years ago
When trying to reproduce it I'll get that error :
"Fatal error: Call to undefined method DOMText::getAttribute() in
/x/phpQuery.class.php on line 2170"

Original comment by nicolas....@gmail.com on 12 Oct 2008 at 2:40

GoogleCodeExporter commented 9 years ago
Should be fixed in r202. Last fix was in wrong loop, but should display a 
notice...

Original comment by tobiasz....@gmail.com on 16 Oct 2008 at 12:19

GoogleCodeExporter commented 9 years ago
Working... or something like

Having the dom :
<dom>
<div id="#myDiv">
hors paragraphe
<p>Test</p>
hors paragraphe
</div>
</dom>

Doing that :
<php>$myPhpQueryElement->find('#myDiv')->append('hors paragraphe<p>Test</p>hors
paragraphe')->contents()->not('[nodeType=1]')->wrap('<p/>');</php>

Give me the DOM :
<dom>
<div id="#myDiv">
<p/>
<p>hors paragraphe</p>
<p/>
<p>Test</p>
<p>hors paragraphe</p>
</div>
</dom>

So there's two empty P element wraping the first P element.

On the same thing jQuery give me that DOM :
<dom>
<div id="#myDiv">
<p>hors paragraphe</p>
<p>Test</p>
<p>hors paragraphe</p>
</div>
</dom>

Original comment by nicolas....@gmail.com on 16 Oct 2008 at 8:59

GoogleCodeExporter commented 9 years ago
nodeType or any other not-direct attributes aren't supported right now. This 
means
->not('[nodeType=1]') dont do anything. I've created new issue for this 
functionality:
http://code.google.com/p/phpquery/issues/detail?id=61

Have you tested r202 ? Using code below:
$doc = phpQuery::newDocumentHTML('<div id="myDiv"></div>');
$doc['#myDiv']->append('hors paragraphe<p>Test</p>hors paragraphe')
    ->contents()
        ->not('[nodeType=1]')
            ->wrap('<p/>');
I have (in r202):
<div id="myDiv">
<p>hors paragraphe</p>
<p><p>Test</p></p>
<p>hors paragraphe</p>
</div>

Which is expected output (considering no nodeType support).

Original comment by tobiasz....@gmail.com on 16 Oct 2008 at 9:27

GoogleCodeExporter commented 9 years ago
Using the same DOM and :
<php>
$article_element->contents()->not('[nodeType=1]')->wrap('<p/>')->children('p:emp
ty')->remove();
</php>

It display me the error :
"
Fatal error: Call to undefined method DOMText::getElementsByTagName() in
/x/phpQueryObject.php on line 1618"

Original comment by nicolas....@gmail.com on 16 Oct 2008 at 2:12

GoogleCodeExporter commented 9 years ago
Related to Issue #61 - no DOMNode support other than nodeType = 1 (DOMElement, 
normal
tags). Result of contents() can lead to such errors.

Original comment by tobiasz....@gmail.com on 18 Oct 2008 at 8:56