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....



ReadNextTagInString


Unit:SDL_stringl
Class:none
Declaration:function ReadNextTagInString (const InString: string; var StartAt: integer; const TagList: array of string; var Attrib, Contents: string): integer;{Pascal}
int __fastcall ReadNextTagInString(const AnsiString InString, int &StartAt, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, AnsiString &Contents); {C++}

The function ReadNextTagInString scans the string InString for the next XML tag, starting at or after the position StartAt. The read tag is parsed, the tag attributes are returned in the variable parameter Attrib, the contents of the tag are returned in the parameter Contents. 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 StartAt points to the first unprocessed character position.

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: This function cannot be used for HTML tags containing the same HTML tag with different attributes (e.g. <FONT color=#323233>some text <FONT size=3>more text</FONT> additional text</FONT>). In this case the closing </FONT> tag will be associated with the wrong opening tag.

Hint : The declaration of ReadNextTagInString 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 ReadNextTagInString(const AnsiString InString, int &StartAt, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, AnsiString &Contents);

Example: The following sample code shows how to use the function ReadNextTagInString. 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;

...
spos := 1;
xmltag := TXmlTag (ReadNextTagInString (TestStr, spos,
                         xmlTagIds, attrib, contents));
...

 


Last Update: 2023-Jul-09