Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#133 2012-10-26 02:41:32

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

query="//table[@class='observations']//td"

That’s my basic query. I want to replace some text strings within the contents of the TD tag:

  • replace oC with °C
  • replace non-breaking space with a space (when viewing generated source in Firefox, I see a number of   that I want to strip)

Having some difficulty with the syntax!

Offline

#134 2012-10-26 17:05:22

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

nardo wrote:

I want to replace some text strings within the contents of the TD tag:

  • replace oC with °C
  • replace non-breaking space with a space (when viewing generated source in Firefox, I see a number of   that I want to strip)

Something like this could work:

query="//table[@class='observations']//td"
replace=".//text()={$str_replace(oC|°C|$)}%.//text()={$str_replace( | |$)}"
separator="%"

Last edited by etc (2012-10-26 21:39:09)

Offline

#135 2012-10-27 04:40:42

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Another question! I am using url="ftp://ftp2.bom.gov.au/anon/gen/fwo/IDN11060.xml" but it appears the plugin is not parsing that link. That protocol not supported by etc_query?

Offline

#136 2012-10-27 10:06:09

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

nardo wrote:

Another question! I am using url="ftp://ftp2.bom.gov.au/anon/gen/fwo/IDN11060.xml" but it appears the plugin is not parsing that link. That protocol not supported by etc_query?

It is, and this works just fine for me:

<txp:etc_query url="ftp://ftp2.bom.gov.au/anon/gen/fwo/IDN11060.xml"
  markup="xml"
  query="//area"
  wraptag="ul" break="li">
{@description?}: {forecast-period[1]/text[@type="precis"]?}
</txp:etc_query>

Offline

#137 2012-10-27 10:54:02

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Thanks Oleg. I’ve pasted in your example above, and removed everything else from the page – but nothing is returned.

Could it be my PHP installation doesn’t have an extension that your’s does?

Offline

#138 2012-10-27 11:40:56

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

That would be strange, etc_query uses nothing more than php file_get_contents to import data. My php is 5.4, and everything seems to work fine. There is a lag due to slow network connection, but after a second or two the data is here.

Try to pass debug="d" to etc_query to see if the feed is imported.

Offline

#139 2012-10-27 11:49:28

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Preloaded in 3.0031430721283 seconds.

DATA

Loaded in 1.8119812011719E-5 seconds.

Processed in 4.1007995605469E-5 seconds.

So it is loading, I guess.

Within the etc_query container I put some plain text to test:

TEST OUTPUT: {@description?}: {forecast-period[1]/text[@type="precis"]?}@

That “TEST OUTPUT” text is not being displayed on page load.

Offline

#140 2012-10-27 12:02:10

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

Would it be mb_convert_encoding..? Try to pass some weird encoding="abc" to etc_query. And your etc_query version is probably older than 1.2.2, please redownload if so.

Offline

#141 2012-10-27 12:24:16

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Upgraded to 1.2.2. New debug trace added below. Adding encoding="abc" didn’t appear to do anything.

Preloaded in 3.0038778781891 seconds.

DATA xml

Loaded in 1.9073486328125E-5 seconds. 

Processed in 3.7908554077148E-5 seconds.

Should mention that I have other successful etc_query hooks on this site (although I removed them from this page when debugging).

Offline

#142 2012-10-27 13:21:04

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

This Preloaded in 3.0038778781891 seconds. makes me think that your server drops the connection after 3s, but my network knowledge is rather limited. Could you try to replace the line $data = file_get_contents($url); by

$ctx = stream_context_create(array(
    'ftp' => array(
        'timeout' => 15
        )
    )
); 
$data = file_get_contents($url, false, $ctx);

in the plugin code, and report back?

Edit: and please enable txp debug mode.

Edit: no, that does not seem to work. But if you always get Preloaded in 3.00... seconds. trace, I am pretty sure it’s a timeout problem. It takes me some 7s to download from this url.

Last edited by etc (2012-10-27 13:50:13)

Offline

#143 2012-10-27 20:37:32

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

Made that change but no real difference – same output as before (no output) and similar debug trace:

Preloaded in 3.0047500133514 seconds.

DATA xml

Loaded in 2.0027160644531E-5 seconds. 

Processed in 3.9815902709961E-5 seconds.

Thanks for your help Oleg

Offline

#144 2012-10-27 20:50:39

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: etc_query: all things Textpattern

I tried a smaller file – ftp://ftp2.bom.gov.au/anon/gen/fwo/IDT16090.xml – 11kb (as opposed to the other file, 250kb+)

<txp:etc_query url="ftp://ftp2.bom.gov.au/anon/gen/fwo/IDT16090.xml"
  markup="xml" debug="d" 
  query="//area"
  wraptag="ul" break="li">
{.?}
</txp:etc_query>

Similar debug trace:

Preloaded in 3.0033280849457 seconds.

DATA xml

Loaded in 2.0027160644531E-5 seconds. 

Processed in 4.0054321289062E-5 seconds.

Just for comparison…

Offline

Board footer

Powered by FluxBB