String Search Parsing

 

The CLI Parser can be used to parse CLI response that is in the form of message stream. It consists of an XML-based template that has delimiter definitions is used in splitting the message stream into strings or tokens.

 

The parsing of the response is based on a set of delimiters in a delimiter list. The delimiters are usually strings or characters, which are used to split the response message into a number of tokens, each token being part of the response. The splitting of tokens takes place in the order of occurrence of the delimiters.

 

The following table gives details of various tags used to form an XML-based String Search Rule file.

 

Tag Description

PATTERN-DEFN-LIST

It contains a list of all patterns definitions. It is optional and need not be used if pattern matching is not used.

PATTERN-DEFN

It defines a pattern and the appropriate option used for pattern matching. There must be one or more PATTERN-DEFN elements.

TOKEN

Tokens are strings, obtained using Delimiter definitions. It has the following attributes:

DELIMITER :

DESCR : contains a description of the token.

TRIM

Truncates multiple occurrences of a particular character.

MATCH

It contains the patterns that are to be matched with the response. It contains a list of PATTERNs.

PATTERN

It contains the Pattern definition.

PARAM

It contains a list of parameters that are to be extracted from the response message. It has the following attributes.

NAME : It is used to assign a name to the parameter.

VALUE : It is used to obtain the token at particular position.

 

The following example illustrates the usage parsing a response.

 

<PATTERN-DEFN-LIST>

<PATTERN-DEFN NAME="comtype" VALUE="Serial" />

<PATTERN-DEFN NAME="hardware" VALUE="Hardware" />

</PATTERN-DEFN-LIST>

<TOKEN DESCR="Level 3">

<DELIMITER VALUE=" " />

<MATCH>

<PATTERN NAME="comtype" ACTION="SUBS">

<PARAM NAME="Id" VALUE="$1"/>

<PARAM NAME="Status" VALUE="$3"/>

</PATTERN>

</MATCH>

</TOKEN>

 

PATTERN-DEFN-LIST

 

Contains a list of PATTERN-DEFN (pattern definitions). The pattern definitions are mappings between a pattern name and a pattern, where pattern is some string that may occur within the message.

 

PATTERN-DEFN

 

As described above, PATTERN-DEFN contain the NAME and VALUE attributes within them. The NAME attribute is used to map with the actual pattern that may occur in the response. In the MATCH definitions, the patterns are referred to using their corresponding NAMEs. For example,

 

<PATTERN-DEFN NAME="encaps" VALUE="Encapsulation" />

 

maps the name 'encaps' with the pattern Encapsulation. Inside the MATCH definitions, the patterns are referred with this name (encaps). Whenever the parser encounters the name 'encaps' it searches for the pattern 'Encapsulation' in the message.

 

TOKEN

 

This is the basic tag used to define a token within a message. Tokens are basically strings, which are obtained using delimiter definitions. The delimiters are given as a list of values inside the TOKEN node. The message is parsed and split into tokens based on the occurrence of any one of the delimiters in the DELIMITER list. TOKEN can contain another TOKEN within it in a nested manner. At each level, the String tokens are obtained based on the delimiters at that level.

 

DELIMITER

 

This is the tag that is used to define a delimiter. Multiple delimiters can occur within a token. The string tokens from the message are obtained using these values. For example,

 

<DELIMITER VALUE="\n" />

 

Defines the delimiter with the new line as the value. If we have the following response message,

 

<token1>\n<token2>\n<token3>

 

Where token1, token2, etc, are any string, then the message is split into <token1>, <token2>, etc.

 

MATCH

 

This contains the patterns that are to be matched in the response. It contains a list of PATTERNs. Each level of the TOKEN tag may contain a MATCH with a list of PATTERN definitions. Corresponding action to be taken inside when the parser finds a match is defined inside the PATTERN tag.

 

PATTERN

 

As described above, it contains the Pattern definition. It contains the NAME and ACTION attributes. The NAME attribute is to identify the specific pattern in the PATTERN-DEFN list. The ACTION attribute defines the action that has to be taken, if a match is found. Currently supported values for ACTION are

PARAM

 

This tag is used within a PATTERN containing the ACTION attribute value as SUBS. The PARAM tag contains a list of parameters that are to be extracted from the response message. The NAME attribute is used to assign a name to the parameter.

 

The value is obtained from the tokens at that level based on the position specified by the user. The token positions are relative to the matched token. The positions should be prefixed with a $ sign to indicate that the values are to be obtained from the tokens in the message. If it does not start with a $, it is not considered as a position and a direct substitution of provided value is performed. The VALUE attribute can be given in any one of the following formats:

For example:

 

<PATTERN NAME="encaps" ACTION="SUBS">

<PARAM NAME="Encapsulation" VALUE="$1"/>

</PATTERN>

 

Note: The PATTERN definition list should contain the patterns defined in the order in which they may occur in the response message. Only this way it is possible to differentiate multiple groups of the same set of parameters present in the response.

 

Related Topics



Copyright © 2009 ZOHO Corp. All Rights Reserved.