Jump to content

A little bit of xml


stanoliver
 Share

Recommended Posts

My aim is to output a very basic xml document which should be styled with a few css-styles.

<?xml version = "1.0"?>
<contact-info>
   <name>Donal Duck</name>
   <company>Superducks</company>
   <phone>(011) 123-4567</phone>
</contact-info>

How do I implement it with processwire?

Link to comment
Share on other sites

It really depends how your utilizing pages. For example:

<?php
header("Content-type: text/xml");

$people = $pages->find('template=person'); // or whatever your template is

$out = "<?xml version = \"1.0\"?>";
$out .= "<contact-info>";

foreach($people as $person) {
  $out .= "<name>" . person->title . "</name>"; // whatever field is storing the info
  $out .= "<company>" . person->company . "</company>"; // whatever field is storing the info
  $out .= "<phone>" . person->phone . "</phone>"; // whatever field is storing the info

}


$out .= "</contact-info>";
echo $out;

?>

The above would find all "people" and output them in contact info (well, everyone's info would be place inside the contact info tags). You could just move those tags inside the foreach loop if you needed each tag to have their own. Alternatively, you could use $pages->get() method to get a certain page (person. A little bit more information regarding your template structure could help us better give advice/pointers.

Edited by louisstephens
mistyped a few variables
  • Like 1
Link to comment
Share on other sites

@louisstephens Yes, your examples already helps. Do you know if the xml-syntax would also work with the new page meta or does page meta need json-syntax

Basicly I just looking for comfortable ways/ideas how to get data (even better data rows) out of html tables, csv-files, xml-files etc. and vice verca for outputting them in the frontend. Let's say I have a row in a csv-file with the entries '100','200','300' (representing prices: '100'->first price ...)

At last coming back to your example from above: How would I need to change your code from above to get an export to an .csv-file?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...