The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



DetectNextTagInString


Unit:SDL_stringl
Class:none
Declaration:function DetectNextTagInString (const InString: string; var StartIdx, StopIdx: integer; const TagList: array of string; var Attrib: string; var IsClosingTag: boolean): integer; {Pascal}
int __fastcall DetectNextTagInString(const AnsiString InString, int &StartIdx, int &StopIdx, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, bool &IsClosingTag); {C++}

The function DetectNextTagInString scans the string InString for the next XML tag identfier (either closing or opening tag), starting at or after the position StartIdx. The read tag is parsed, and the tag attributes are returned in the variable parameter Attrib. The positions of the beginning and the end of the tag are returned in the variable parameters StartIdx and StopIdx.

The function returns the index of the tag in the TagList. If the tag is not contained in the list, the index of the last tag of the tag list is returned. It is therefore recommended to include a dummy tag which indicates an invalid tag. The variable parameter IsClosingTag returns TRUE if the tag is a closing tag, otherwise a FALSE value is returned.

Hint 1: The returned tag index is base zero, i.e. it can be used as the ordinal of a corresponding enumerated type declaration (see example below).

Hint 2: The declaration of DetectNextTagInString in C++ slightly differs from the Pascal declaration (note the extra parameter TagList_Size which specifies the highest index of the TagList array):
int __fastcall DetectNextTagInString(const AnsiString InString, int &StartIdx, int &StopIdx, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, bool &IsClosingTag);

Example: The following sample code shows how to use the function DetectNextTagInString. The valid XML tags are defined in the constant string array xmlTagIds. Note that the last tag is a dummy tag to account for invalid tags. 
type                                    {valid xml tags}
  TXmlTag = (xmlSizeX, xmlSizeY, xmlNrInsens, xmlMaxNeighb,
             xmlMaxSteps, xmlMaxAlpha, xmlInvalid);

const                                   {xml tag names}
  xmlTagIds : array[xmlSizeX..xmlInValid] of string =
            ('sizex', 'sizey', 'nrinsens', 'maxneighb',
             'maxsteps', 'maxalpha', 'invalidtag');

var
  attrib       : string;
  contents     : string;
  xmlTag       : TXmlTag;
  spos         : integer;
  epos         : integer;
  isclosingtag : boolean;

...
spos := 1;
xmltag := TXmlTag (DetectNextTagInString (TestStr, spos, epos,
                            xmlTagIds, attrib, isclosingtag));
...

 


Last Update: 2012-Oct-20