The following example shows how the elements and attributes stored in the buffer provided by the application are written to the XML file. In addition to the elements and attributes, an example for the additional content is provided. For further information, also refer to the EcoStruxure Machine Expert XML File Handling Example Guide.
The buffer provided by the application of type XmlItems contains elements to be written to the XML file.
Array Index |
diParentIndex |
sName |
sValue |
etType |
diNumOfAttributes |
---|---|---|---|---|---|
0 |
-1 |
|
– |
1 |
0 |
1 |
0 |
|
|
1 |
0 |
2 |
0 |
|
– |
1 |
0 |
3 |
2 |
|
– |
1 |
1 |
4 |
3 |
|
|
2 |
1 |
5 |
3 |
|
|
1 |
2 |
6 |
5 |
|
|
2 |
1 |
7 |
5 |
|
|
2 |
2 |
PROGRAM SR_Example
VAR
fbWrite : FFU . FB_XmlWrite ;
fbXmlUtil : FFU . FB_XmlItemsUtility ;
astXmlItems : FFU . XmlItems ;
xCmdWrite : BOOL ;
sComment : STRING ( 255 ) := 'This is the user comment.' ;
sExternalDTD : STRING := '<!DOCTYPE AAA SYSTEM "example.dtd">' ;
stHeader : FFU . ST_XmlUserDefinedHeader ;
xInitDone : BOOL ;
END_VAR
IF NOT xInitDone THEN
xInitDone := TRUE ;
SysMem . SysMemSet ( ADR ( astXmlItems ) , 0 , SIZEOF ( astXmlItems ) ) ;
fbXmlUtil . InitializeXmlItems ( 'AAA' , astXmlItems ) ;
fbXmlUtil . AddSubElement ( 'BBB' ) ;
fbXmlUtil . ValueOfSelectedElement := '1st bbb' ;
fbXmlUtil . AppendElement ( 'BBB' ) ;
fbXmlUtil . AddSubElement ( 'CCC' ) ;
fbXmlUtil . AddAttribute ( 'id' , '1' ) ;
fbXmlUtil . AddSubElement ( 'DDD' ) ;
fbXmlUtil . ValueOfSelectedElement := 'ddd' ;
fbXmlUtil . AddAttribute ( 'id' , '1' ) ;
fbXmlUtil . AddAttribute ( 'activate' , 'TRUE' ) ;
END_IF
stHeader . sUserComment := sComment ;
stHeader . pbyAdditionalContent := ADR ( sExternalDTD ) ;
stHeader . udiNumBytesToWrite := INT_TO_UDINT ( Standard . LEN ( sExternalDTD ) ) ;
fbWrite (
i_xExecute := xCmdWrite ,
i_sFilePath := './myfiles/Example.xml' ,
i_xOverwriteFile := ,
i_sRootElement := ,
i_refXmlItems := astXmlItems ,
i_stUserDefinedHeader := stHeader ,
i_timTimeout := ,
q_xDone => ,
q_xBusy => ,
q_xError => ,
q_etResult => ,
q_sResultMsg => ) ;