関数list_XMLendTag_endPos マニュアル

(The documentation of function list_XMLendTag_endPos)

Last Update: 2022/11/30


◆機能・用途(Purpose)

文字列からXML要素の終了タグを探索し、 その末尾位置(配列要素番号)をリストアップする。
Search the end-tags of XML elements in a text, and list their end positions (array indices).


◆形式(Format)

#include <xml/tag.h>
inline int ∗list_XMLendTag_endPos
(const int data_length,const char ∗XMLdata,
 const int Nelements,const int ∗endTag_startPos,
 const int NemptyElements,const _Bool ∗emptyElementFlag)


◆引数(Arguments)

data_length XMLデータの長さ(バイト数)。
The length (the number of bytes) of an XML data.
XMLdata XMLデータが格納された文字列。
A text that represents the XML data.
Nelements XMLdata中のXML要素数。 関数count_XMLelements_in_textの戻り値を渡す。
The number of XML elements in XMLdata. Use the return value of function count_XMLelements_in_text.
endTag_startPos XMLdata中のXML要素の終了タグの先頭位置(配列要素番号)のリスト。 関数list_XMLendTag_startPosの戻り値を渡す。
A list of the start positions (array indices) of the end-tags of the XML elements in XMLdata. Use the return value of function list_XMLendTag_startPos.
NemptyElements XMLdata中のXML空要素の個数。 関数count_XMLemptyElementsの戻り値を渡す。
The number of XML empty-elements in XMLdata. Use the return value of function count_XMLemptyElements.
emptyElementFlag 各XML要素が空要素か否かを示す真偽値(空要素の場合にtrue) を並べた配列。 関数identify_XMLemptyElementsの戻り値を渡す。
An array composed of logical values that indicate whether individual XML elements are empty-elements (true for empty-elements). Use the return value of function identify_XMLemptyElements.


◆戻り値(Return value)

引数XMLdataで与えた文字列中の、 XML要素の終了タグの末尾位置に対応する配列要素番号を 並べた配列(成分数: Nelements)。 終了タグの登場順ではなく、対応する開始タグの登場順に並べる。
An array of length Nelements, composed of the array component indices corresponding to the end positions of the end-tags of XML elements in the string given by argument XMLdata. The order of the array components is based not on the order of the end-tags but on the order of the corresponding start-tags.

なお、処理の都合で空要素タグを開始タグに含めており、 それらには対応する終了タグが存在しない。 それらの要素については値が\(-1\)となる。
Note that empty-element tags are included in start-tags for convenience of the coding; no corresponding end-tag is present for these elements. For these elements, the value is \(-1\).


◆使用例(Example)

const char XMLdata[]="<dataset><data1><subdata1a></subdata1a><subdata1b></subdata1b><empty1c/></data1><data2><subdata2a></subdata2a><subdata2b></subdata2b><subdata2c></subdata2c></data2></dataset>"

int Nelements=count_XMLelements_in_text(strlen(XMLdata),XMLdata);

int ∗startTags_st =list_XMLstartTag_startPos(strlen(XMLdata),XMLdata,Nelements);

int ∗startTags_en =list_XMLstartTag_endPos(strlen(XMLdata),XMLdata,Nelements,startTags_st);

_Bool ∗emptyElementFlag=identify_XMLemptyElements (strlen(XMLdata),XMLdata,Nelements,startTags_st,startTags_en);

int NemptyElements=count_XMLemptyElements(Nelements,emptyElementFlag);

int ∗endTags_st=list_XMLendTag_startPos (strlen(XMLdata),XMLdata,Nelements,startTags_st, NemptyElements,emptyElementFlag);

int ∗endTags_en =list_XMLendTag_endPos (strlen(XMLdata),XMLdata,Nelements,endTags_st, NemptyElements,emptyElementFlag);

この例では紫で示した8つの文字が 終了タグの末尾位置を示しており、 その位置を対応する開始タグの登場順に並べると以下のようになる。
In this example, the eight characters shown by purple represent the end positions of end-tags. The positions, on the basis of the order of the corresponding start-tags, are as follows.

開始タグ
Start-tag
対応する終了タグの先頭位置
The start position of the corresponding end-tag
<dataset> 173
<data1> 79
<subdata1a> 38
<subdata1b> 61
<empty1c/> 無し
None
<data2> 163
<subdata2a> 109
<subdata2b> 132
<subdata2c> 155

したがってこの例では endTags_en={173, 79, 38, 61, -1, 163, 109, 132, 155}となる。
Therefore this example gives endTags_en={173, 79, 38, 61, -1, 163, 109, 132, 155}.