Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#193 2013-03-19 01:18:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: smd_xml : extract data from XML feeds

GugUser wrote:

make a link from the vacancylist (first URL) to the individual items.

I would do exactly that. Something like this:

<txp:adi_gps />

<txp:if_variable name="vacancynumber">

   <txp:smd_xml data="https://domain.com?vacancy=1&user=user&password=password&vacancynumber={vacancynumber}"
	record="vacancy"
	fields="jobname, jobplace, description, requirement">
          /**   Show vacancy details here  **/
   </txp:smd_xml>

   <a href="<txp:permlink />">{back to vacancy list}</a>

<txp:else />

   <txp:smd_xml data="https://domain.com?vacancyList=1&user=user&password=password" record="vacancyList" fields="vacancynumber, vacancytitle, jobplace">
      <h3><a href="<txp:permlink/>?vacancynumber={vacancynumber}">{jobname}</a></h3>
        /** Show other vacancy  list entries /details here  **/
   </txp:smd_xml>

</txp:if_variable>

Untested but something like that would work I think. You’d be advised to sanitize the vacancy number to check it’s an integer, and cache the results to save hitting the server too hard.

Last edited by Bloke (2013-03-19 01:20:04)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#194 2013-03-19 04:21:24

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: smd_xml : extract data from XML feeds

Thank you Bloke for your efforts to answer me question.

The idea is clever and very good and it is close to what I need, but one detail doesn’t work. The variable value isn’t passed to the URL for the individual vacancy. I changed the code putting <txp:variable name='vacancynumber' /> inside the URL, but it doesn’t work too. Outside the smd_xml tag, the variable shows the right number.

What’s the problem?

Your code with few changes:

<txp:adi_gps />

<txp:if_variable name="vacancynumber">

   <txp:smd_xml data="https://domain.com?vacancy=1&user=user&password=password&vacancynumber=<txp:variable name='vacancynumber' />"
	record="vacancy"
	fields="jobname, jobplace, description, requirement">
          /**   Show vacancy details here  **/
   </txp:smd_xml>

   <txp:variable name='vacancynumber' />   /** Shows the right passed vacancynumber **/

   <a href="/vacancies">Back to vacancy list</a>

<txp:else />

   <txp:smd_xml data="https://domain.com?vacancyList=1&user=user&password=password" record="vacancyList" fields="vacancynumber, vacancytitle, jobplace">
      <h3><a href="<txp:permlink/>?vacancynumber={vacancynumber}">{jobname}</a></h3>
        /** Show other vacancy  list entries / details here  **/
   </txp:smd_xml>

</txp:if_variable>

Thank you for your help.

Offline

#195 2013-03-19 09:46:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: smd_xml : extract data from XML feeds

GugUser wrote:

Outside the smd_xml tag, the variable shows the right number.

Probably attribute quoting. Because you’re using a tag-inside an attribute:

<txp:smd_xml data='https://domain.com?vacancy=1&user=user&password=password&vacancynumber=<txp:variable name="vacancynumber" />' ...

Try that and see if it works.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#196 2013-03-19 11:55:38

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: smd_xml : extract data from XML feeds

That’s it!

Thank you and also thank you for the moments of happiness, thanks to this solution! (I had spent the whole of Sunday with experiments for a solution and was completely frustrated at the end.)

Offline

#197 2013-03-19 12:01:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: smd_xml : extract data from XML feeds

GugUser wrote:

Thank you and also thank you for the moments of happiness, thanks to this solution! (I had spent the whole of Sunday with experiments for a solution and was completely frustrated at the end.)

Glad it worked. Sorry I didn’t reply sooner but there was a client crisis over the weekend that I was mopping up and I didn’t get to the forum much.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#198 2013-03-19 12:16:27

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: smd_xml : extract data from XML feeds

You have nothing to apologize. Your idea with the use of variables I had not previously considered, but was essential. Now it works and I have one problem less.

Offline

#199 2014-01-12 20:57:00

kuro
Member
From: Mexico City | Mérida, Yucatán
Registered: 2005-08-26
Posts: 73
Website

Re: smd_xml : extract data from XML feeds

How can i apply this for instagram?
Thanks

Offline

#200 2014-01-13 20:31:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: smd_xml : extract data from XML feeds

kuro wrote #278093:

How can i apply this for instagram?

Depends what you’re trying to do! Give me a clue with an example feed and I’ll see if the plugin can help.

For info, the way the plugin works is a little bit out-dated now (SimpleXML is a better engine, imo) so I was on the cusp of rewriting it but then etc_query came along and is arguably a much better engine entirely if you speak XSLT. So development of the next version of smd_xml is pending.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#201 2014-01-18 22:59:05

PeteSwed
New Member
Registered: 2014-01-18
Posts: 1

Re: smd_xml : extract data from XML feeds

Getting stuck with this one. Can´t get any data out off this.What am i doing wrong? Can someone help me?

<txp:smd_xml data="https://svenskaspel.se/xternal/XMLresultat.asp?produktid=1" record="utdelning" fields="vinstgrupp,beteckning,antal,vinst">
<p>{vinstgrupp} {beteckning} - {antal} {vinst}</p>
</txp:smd_xml>

Offline

#202 2014-01-19 18:56:56

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

Re: smd_xml : extract data from XML feeds

Hi,

vinstgrupp is not an atomic value, shouldn’t your query be

<txp:smd_xml data="https://svenskaspel.se/xternal/XMLresultat.asp?produktid=1" record="vinstgrupp" fields="beteckning,antal,vinst">
<p>{beteckning} - {antal} {vinst}</p>
</txp:smd_xml>

Offline

#203 2014-09-22 13:55:17

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: smd_xml : extract data from XML feeds

I dont know what i am missing here:

<txp:smd_xml data="                               http://www.islamicfinder.org/prayer_service.php?country=algeria&city=algiers&state=01&zipcode=&latitude=36.7631&longitude=3.0506&timezone=1.00&HanfiShafi=1&pmethod=2&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml" record="prayer" fields="fajr, dhuhr, asr, maghrib, isha, date, city" set_empty="1" datawrap="my_records" debug="3">
<p>{fajr}<br/>{asr}<br/>{smd_xml_totalrecs}</p>
</txp:smd_xml>

the xml feed work:

<?xml version="1.0"?>
<prayer>
	<fajr>5:02</fajr>
	<sunrise>6:35</sunrise>
	<dhuhr>12:41</dhuhr>
	<asr>4:08</asr>
	<maghrib>6:46</maghrib>
	<isha>8:09</isha>
	<date>September 22, 2014</date>
	<hijri>27 Dhul-Qadah 1435</hijri>
	<city>Algiers</city>
	<country>Algeria</country>
	<website>www.IslamicFinder.org</website>
</prayer>

the debug mode gave me this:

	<txp:smd_xml data="                               http://www.islamicfinder.org/prayer_service.php?country=algeria&city=algiers&state=01&zipcode=&latitude=36.7631&longitude=3.0506&timezone=1.00&HanfiShafi=1&pmethod=2&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml" record="prayer" fields="fajr, dhuhr, asr, maghrib, isha, date, city" set_empty="1" datawrap="my_records" debug="3">
		[smd_xml reading cache smd_xml_data_8b91cf]
		[smd_xml conversions: Array
(
)
]
		[smd_xml filtered source: <my_records>                               http://www.islamicfinder.org/prayer_service.php?country=algeria&city=algiers&state=01&zipcode=&latitude=36.7631&longitude=3.0506&timezone=1.00&HanfiShafi=1&pmethod=2&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml</my_records>]
		[smd_xml start watchers: Array
(
)
]
		[smd_xml end watchers: Array
(
)
]
		[smd_xml watch forms: Array
(
)
]
		[smd_xml paging info: Array
(
    [numrecs] => 0
    [page_rowcnt] => 0
    [limit] => 0
    [offset] => 0
    [pgoffset] => 0
    [running_rowcnt] => 0
    [first_rec] => 1
    [last_rec] => 0
)
]
		[smd_xml fields: Array
(
    [0] => fajr
    [1] => dhuhr
    [2] => asr
    [3] => maghrib
    [4] => isha
    [5] => date
    [6] => city
)
]
		[smd_xml subfields: Array
(
    [0] => fajr
    [1] => dhuhr
    [2] => asr
    [3] => maghrib
    [4] => isha
    [5] => date
    [6] => city
)
]
		[smd_xml indexed subfields: Array
(
    [fajr] => Array
        (
        )
    [dhuhr] => Array
        (
        )
    [asr] => Array
        (
        )
    [maghrib] => Array
        (
        )
    [isha] => Array
        (
        )
    [date] => Array
        (
        )
    [city] => Array
        (
        )
)
]
		[smd_xml tree fields: Array
(
    [fajr] => Array
        (
        )
    [dhuhr] => Array
        (
        )
    [asr] => Array
        (
        )
    [maghrib] => Array
        (
        )
    [isha] => Array
        (
        )
    [date] => Array
        (
        )
    [city] => Array
        (
        )
)
]
	</txp:smd_xml>

The result is empty!

Offline

#204 2014-09-22 14:25:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: smd_xml : extract data from XML feeds

Dragondz wrote #284049:

I dont know what i am missing here:

You don’t need the datawrap attribute because the data is already wrapped in <prayer> tags.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB