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.
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 |
AAA |
– |
1 |
0 |
1 |
0 |
BBB |
1st bbb |
1 |
0 |
2 |
0 |
BBB |
– |
1 |
0 |
3 |
2 |
CCC |
– |
1 |
1 |
4 |
– |
id |
1 |
2 |
1 |
5 |
3 |
DDD |
ddd |
1 |
2 |
6 |
– |
id |
1 |
2 |
1 |
7 |
– |
activate |
TRUE |
2 |
2 |
PROGRAM SR_Example
VAR
fbWrite :FFU.FB_XmlWrite;
astXmlItems :FFU.XmlItems;
xCmdWrite :BOOL;
sComment :STRING(255) := 'This is the user comment.';
sExternalDTD :STRING := '<!DOCTYPE AAA SYSTEM "example.dtd">';
stHeader :FFU.ST_XmlUserDefinedHeader;
END_VAR
stHeader.sUserComment := sComment;
stHeader.pbyAdditionalContent := ADR(sExternalDTD);
stHeader.udiNumBytesToWrite := INT_TO_UDINT(Standard.LEN(sExternalDTD));
fbWrite(
i_xExecute := xCmdWrite,
i_sFilePath := '/sd0/Example.xml',
i_xOverwriteFile := ,
i_sRootElement := ,
i_refXmlItems := astXmlItems,
i_stUserDefinedHeader := stHeader,
i_timTimeout := ,
q_xDone => ,
q_xBusy => ,
q_xError => ,
q_etResult => ,
q_sResultMsg => );
<?xml version="1.0" encoding="ASCII"?>
<!--This is the user comment.-->
<!DOCTYPE AAA SYSTEM "example.dtd">
<AAA>
<BBB>1st bbb</BBB>
<CCC id="1">
<DDD id="1" activate="TRUE">ddd</DDD>
</CCC>
</BBB>
</AAA>