[r51]: / trunk / library / XmlControl / FB_XmlControl / svnobj  Maximize  Restore  History

Download this file

72 lines (70 with data), 8.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(*
Filebuffersize is default 4096 bytes and can be set via Gvl_Param_XmlControl
Usage example:
1. Initiate
    VAR
        XML : FB_XMLControl;
        Buffer: STRING(GVL_Param_XmlControl.udiMaxFileSize);
        //or
    XML.WriteDocumentHeader( '<?xml version=\"1.0\" encoding=\"UTF-8\"?>');
2. Compose a tag with a parameters:
XML: <MyTag ParaName = "11" />
    XML.newTag(sTagName: = 'MyTag');
    XML.newPara(sName: = 'ParaName', sPara: = sValue);
    XML.CloseTag();
3. Add tag value:
XML: <MyTag> MyText </ MyTag>
    XML.newTag(sName := 'MyTag');
    XML.newTagData(sTagData :='MyText');
4. Jump to the beginning of the XML data
XML.toStartBuffer();
5. Add a comment:
XML: <!-- MyComment -->
    XML.newComment(sTagName: = 'MyComment');
6. Returns the next tag from the current position in buffer
XML.NextTag();
7. Output the parameter of the tag
XML.NextPara(sPara: = LastValue);
Feedback: sPara returns the value found (string)
*)
//{attribute 'hide_all_locals'}
FUNCTION_BLOCK FB_XmlControl
VAR
    Buffer : FB_StringBuffer;
    TagList : FB_StringBuffer;
    sTags : T_MaxString;
    TagListSeek : FB_StringBuffer;
    sTagsSeek : STRING;
    Tag : FB_StringBuffer;
    sTag : T_MaxString;
    xTagOpen: BOOL;
    iSelect : UDINT;
    iSelectStart : UDINT;
    iSelectEnd : UDINT;
    iSelectStartPara : UDINT;
    iSelectEndPara : UDINT;
    iSelectTagClose : UDINT;
    iSelectStartValue : UDINT;
    iSelectEndValue : UDINT;
    udiSearchPos : UDINT; 
END_VAR
VAR CONSTANT
    TAG_OPEN : STRING(1) := '<';
    TAG_CLOSE : STRING(1) := '>';
    END_TAG_CLOSE : STRING(4) := '/>';
    SPACE : STRING(1) := ' ';
    EQUALS : STRING(1) := '=';
    QUOTE : STRING(1) := '"';
    BACK_SLASH : STRING(1) := '\';
    FORWARD_SLASH : STRING(1) := '/';
    OPEN_COMMENT : STRING(5) := '<!-- ';
    CLOSE_COMMENT : STRING(4) := ' -->';
    TAB : STRING(2) := '$T';
	CR_LF : STRING(4) := '$R$N';
  
	//$OD : ASCII code for carriage return (CR)
	//$$ : to add a $R
	//$' : to add ' (apostrophe)
	//$L or $l : line feed
	//$N or $n : new line
	//$P or $p : next page
	//$R or $r : end of line