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



ReadNextTagInStream


Unit:SDL_streams
Class:none
Declaration:function ReadNextTagInStream (const AStream: TStream; TagList: array of string; var Attrib, Contents: string): integer; {Pascal}
int __fastcall ReadNextTagInStream(const Classes::TStream* AStream, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, AnsiString &Contents); {C++}

The function ReadNextTagInStream scans the stream AStream for the next XML tag, starting at or after the current stream position. 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 stream position after performing ReadNextTagInStream points to the first character after the read tag.

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 3: The declaration of ReadNextTagInStream 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 ReadNextTagInStream(const Classes::TStream* AStream, const AnsiString * TagList, const int TagList_Size, AnsiString &Attrib, AnsiString &Contents);

Example: The following sample code shows how to use the function ReadNextTagInStream. 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;
  AStream  : TMemoryStream;
  xmlTag   : TXmlTag;

...
xmltag := TXmlTag (ReadNextTagInStream (AStream, xmlTagIds, attrib, contents));
...

 


Last Update: 2012-Okt-20