Xpz generation

Unofficial Content

xpz generation

As we have already said, xpz generation is performed from the dkts. 
Dkts combine  C# code and GX (KMW) code. The following appears at the beginning of the dkt:

<%@ Template Language="C#" TargetLanguage="GX" Description="Work With Main Template" %>

With C#, the instance xml is scanned and processed and a new output xml is written from there (the xpz).   
The xpz is also an xml with a specific format, something like the following:

<ExportFile>
  <Model>                                          >>> Info on the model props.
    <Id>1</Id>
    <Name>NewKB</Name>
    <AttLen>30</AttLen>
    <TblLen>30</TblLen>
    <ObjLen>30</ObjLen>
    </Model>
  <KMW>                                             >>> Info on the KB
    <MajorVersion>2</MajorVersion>
    <MinorVersion>2</MinorVersion>
    <Path>D:\AJAXSample</Path>
    <MaxGxBuildSaved>2601</MaxGxBuildSaved>
  </KMW>
  <GXObject>                                        >>> The info of the objects   
<Transaction>                                           located within xpz starts here
      <Info>                                          (in this case it is just a TRN)
        <Name>Client</Name>
        <Description>Client</Description>
      </Info>
       ..............................
       ..............................
      <Structure>                                       >>> Info of the structure
        <Source>
        ..............................
        </Source>
        <LevelInfo>                                      >>> Info of the attributes
          <KeyId>1</KeyId>
          <Name>Client</Name>
          <Description>Client</Description>
        </LevelInfo>
        <AllowNulls>
          <Name>ClientName</Name>
          <Value>No</Value>
        </AllowNulls>
      ..............................
      </Structure>
      <Variable>                                         >>> Info of the variables
        <Name>Today</Name>
        <Title>Today</Title>
        <Type>Date</Type>
        <Length>8</Length>
        <Decimals>0</Decimals>
        <Picture>99/99/99</Picture>
        <Property>
          <Type>string</Type>
          <Name>ATT_PICTURE</Name>
          <Value>99/99/99</Value>
        </Property>
      </Variable>
..............................
<Form>WinForm</FormInfo>                                  >>> Info of the forms
<HTMLForm>WebForm</HTMLForm>
<Events>
..............................
</Events>                                                 >>> Info of the events
..............................
    </Transaction>
</GXObject>
<GXObject>
   <Attributes>
    ..............................
    </Attributes>
     ..............................
  </GXObject>
</ExportFile>

Therefore, the instance is scanned with the templates and the xpz is written as described above. 
Thus, we find the following in the templates: 

<GXObject>                                                 >>> This is written in the xpz
<Transaction>                                              >>> This is written in the xpz
<%
foreach (XmlNode subNode in trnNode.SelectNodes("*"))      >>> The instance scanning starts
{
switch (subNode.Name)
{
case "LastUpdate" :
// Strip LastUpdate info.
break;
case "HTMLForm" :
if (updateWebForm)
{
%>
<%@ CallSubTemplate WWTrnWebForm Transaction='transaction' TransactionNode='TransactionNode' HTMLFormNode='subNode' PgmDescVarId='GetVarId(trnNode, "PgmDesc")' GxRemoveVarId='GetVarId(trnNode, "GxRemove")' Update='Update' %>
<% }
else
{
%>
<%= subNode.OuterXml %>                                 >>> All the node info is written in the xml
................
case "Events" :
<Events>
................
</Events>
................
</Transaction>
</GXObject>

Some interesting classes to generate xpz may be the following: 
HTMLToKMW - e.g.: TD is used for cells
WinToKMW

Example of the use of these classes:

Imagen11

These classes help writing the xml (cells, controls, etc.) 
In this case, HTMLForm and HTMLBlock tags are directly written in the xpz as well as the result of the variables between <% and %>.
More information in Documentation.chm.

Besides, InnerXml and OuterXml methods are used to write sub-nodes in xpz.
These methods are used as follows, let's say you must generate the following nodes in xpz:

Image3