Monday, 25 August 2008

Creating Nominet EPP messages using Smarty

As mentioned in a previous post on Connecting to Nominet EPP with PHP, the Smarty templating system is an easy to use way to create EPP messages without having to resort to complicated XML generation.

For information on how to get started with Smarty, see my Introduction To Smarty.

EPP requests are standard XML documents with a few variables that change on each request.

For example, to query information related to a domain name the info command is used:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
epp-1.0.xsd">
<command>
<info>
<domain:info
xmlns:domain="http://www.nominet.org.uk/epp/xml/nom-domain-1.0"
xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/nom-domain-1.0
nom-domain-1.0.xsd">
<domain:name>webma.co.uk</domain:name>
</domain:info>
</info>
<clTRID>EXAMPLE-12345</clTRID>
</command>
</epp>

The only two elements that change in this XML from one request to the next are the domain name and the clTRID which is the client transaction id, therefore a smarty template of the following:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
epp-1.0.xsd">
<command>
<info>
<domain:info
xmlns:domain="http://www.nominet.org.uk/epp/xml/nom-domain-1.0"
xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/nom-domain-1.0
nom-domain-1.0.xsd">
<domain:name>{$domain_name}</domain:name>
</domain:info>
</info>
<clTRID>{$transaction_id}</clTRID>
</command>
</epp>

would fit the purpose, assuming this is saved in a file called info.tpl, to get the correct XML for an info request use the following PHP code:

$smarty->assign('domain_name','webma.co.uk');
$smarty->assign('transaction_id','TAG_NAME-123');
$xml = $smarty->fetch('info.tpl');

This can be repeated for any EPP request needed very simply.

No comments: