Using XML Templates

Top  Previous  Next

How do we use XML Templates? First we need to create XML templates for our mainframe screens. These templates are saved into a common directroy. Once we have these templates ready we can use the XmlBroker component and XmlTemplate class as follows:

 

Examples:

 

 VB:

 Private Sub ProduceXml() As String

   'first we instanciate the XmlBroker

   Dim broker1 As TTNBXXmlBroker = new TnbXXmlBroker(telnet)

 

   'then we change its XML producer by assigning an XmlTemplate object

   broker1.Producer = new TTNBXXmlTemplate("c:\My Templates")

 

   'now, the returned Xml will be produced by the XmlTemplate object and

   'the corresponding template file.

   ProduceXml = broker1.Xml

 End Sub

 

 Delphi:

 procedure ProduceXml:String;

 var broker:TTnbXmlBroker;

 begin

   //first we instanciate the XmlBroker

   broker := TTnbXmlBroker.Create(tn3270);

 

   //then we change its XML producer by assigning an XmlTemplate object

   broker.Producer = XmlTemplate.Create('c:\My Templates');

 

   //now, the returned Xml will be produced by the XmlTemplate object and

   //the corresponding template file.

   result := broker.Xml;

 end;

 

We need to tell to XmlTemplate object the directory where the XML template files are located. Then, when the XmlBroker needs to produce a new XML, it ask to the producer (in this case XmlTemplate) if it can produce XML content from the current screen. Then, XmlTemplate object looks for a template that matchs with the current screen and returns true or false according to it. Next, in case it returned true, it is asked to produce the XML content which finally will be the one delivered by XmlBroker's Xml property; in case it returned false, the XmlBroker uses the default producer to generate XML content, returning a generic XML based on HostFields.