Using XML Tags to Define Format

Format templates use XML tags to identify specific information that is to be extracted and the structure of its output when using the GetInfo or GetSessionInfo function.

Specifying the Output Root Tag

The root tag for the Format XML that specified the information to retrieve is <haspformat>. This tag has an optional attribute, root, which specifies the root tag of the output. If this attribute is omitted, the default root tag for the output is <hasp_info>. The following example shows the different outputs that are returned, based on the root tag specified in the Format XML.

Input

Output

<haspformat>...</haspformat>
<hasp_info>...</hasp_info>
<haspformat root="haspscope">...</haspformat>
<haspscope>...</haspscope>

Specifying the Information to be Returned

Obviously the output in the above example is not very useful. You need to extract additional information about the Features. Add child tags to the object (in this case, feature) specifying the information that is required. See Format XML Tags for a list of the available tags.

The Feature IDs would be the most useful information. There are two tags that could be used to extract this information <attribute name="name"> or <element name="name">. The output of the first option adds the extracted information to the tag as an attribute. The output of the second option adds a child tag, with the extracted information stored as simple text inside it.

The following examples demonstrate the difference.

Input

Output

<haspformat>
<feature>
<attribute name="id" />
</feature>
</haspformat>
<hasp_info>
<feature id="0" />
<feature id="2"/>
</hasp_info>
<haspformat>
<feature>
<element name="id" />
</feature>
</haspformat>

 

 

<hasp_info>
<feature>
 <id>0</id>
</feature>
<feature>
<id>2</id>
</feature>
</hasp_info>

Specifying Multiple Types of Information from a Single Object

It is possible to extract multiple types of information from a single object by specifying multiple attribute and/or element tags, one after the other. The following example shows how this method is specified, and the resultant output.

Input

Output

<haspformat>
<feature>
<attribute name="id" />
<element name="license" />
</feature>
</haspformat>

 

<hasp_info>
<feature id="0">
 <license>
<license_type>perpetual</license_type>
</license>
</feature>
<feature id="2">
<license>
<license_type>perpetual</license_type>
<exp_date>1159192194</exp_date>
</license>
</feature>
</hasp_info>

Information from multiple objects can also be extracted in a single Format XML. If the additional object tags are input as child tags, the format of the extracted information is grouped by the parent object. The following example demonstrates how Features can be grouped by Sentinel protection key, using this format.

NOTE    This Format XML will work only with the GetInfo function. For the GetSessionInfo function, the session is logged in to a single Feature. This Format XML will retrieve information only for that Feature.

Input

Output

<haspformat root="hasp_info">
<hasp>
<attribute name="id" />
<feature>
<attribute name="id" />
</feature>
</hasp>
</haspformat>
<hasp_info>
<hasp id="2147518309">
 <feature id="0" />
</hasp>
<hasp id="2068806240" />
<feature id="2" />
</hasp>
</hasp_info>

If both the Sentinel protection key and the Feature were independent children tags of the root tag, two independent lists would have been created, as shown in the following example.

Input

Output

<haspformat root="hasp_info">
<hasp>
<attribute name="id" />
</hasp>
<feature>
<attribute name="id" />
</feature>
</haspformat>
<hasp_info>
<hasp id="2147518309">
<hasp id="2068806240" />
<feature id="0" />
<feature id="2" />
</hasp_info>

 

Using a Format XML Output to Generate a Scope XML

The flexibility available when you specify a Format XML template enables you to use the GetInfo function to generate a Scope XML template. The following example assumes that a program is logged into a Feature and the API's login handle is 50293. The output from the GetInfo function can then be used as a Scope parameter for the LoginScope function. It will limit the login to Features that have the same Sentinel protection key as the login with handle 50293.

Input Scope

Output

<haspscope>
<session handle="50293" />
</haspscope>

Input Format

<haspformat root="haspscope">
<hasp>
<attribute name="id" />
</hasp>
</haspformat>
<haspscope>
<hasp id="2147518309" />
</haspscope>

 

 

 

 

 

Related Topics

Format XML Tags

About XML Tags