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:
VB.NET: Private Sub ProduceXml() As String 'first we instanciate the XmlBroker Dim broker As XmlBroker = new XmlBroker(tn3270)
'then we change its XML producer by assigning an XmlTemplate object broker.Producer = new XmlTemplate("c:\My Templates")
'now, the returned Xml will be produced by the XmlTemplate object and 'the corresponding template file. ProduceXml = broker.Xml End Sub
C#: public string ProduceXml() { // first we instanciate the XmlBroker XmlBroker broker = new XmlBroker(tn3270);
// then we change its XML producer by assigning an XmlTemplate object broker.Producer = new XmlTemplate(@"c:\My Templates");
// now, the returned Xml will be produced by the XmlTemplate object and // the corresponding template file. return broker.Xml; }
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.
|