Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX...

103
Manual | EN TE1000 TwinCAT 3 | PLC Lib: Tc3_JsonXml 9/10/2020 | Version: 1.7

Transcript of Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX...

Page 1: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Manual | EN

TE1000TwinCAT 3 | PLC Lib: Tc3_JsonXml

9/10/2020 | Version: 1.7

Page 2: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback
Page 3: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE1000 3Version: 1.7

Table of contents1 Foreword .................................................................................................................................................. 11

1.1 Notes on the documentation............................................................................................................ 111.2 Safety instructions ........................................................................................................................... 12

2 Overview................................................................................................................................................... 13

3 Function blocks ....................................................................................................................................... 153.1 FB_JsonDomParser ........................................................................................................................ 15

3.1.1 AddArrayMember.............................................................................................................  153.1.2 AddBase64Member .........................................................................................................  153.1.3 AddBoolMember ..............................................................................................................  153.1.4 AddDateTimeMember......................................................................................................  163.1.5 AddDcTimeMember.........................................................................................................  163.1.6 AddDoubleMember..........................................................................................................  163.1.7 AddFileTimeMember .......................................................................................................  173.1.8 AddHexBinaryMember.....................................................................................................  173.1.9 AddInt64Member .............................................................................................................  173.1.10 AddIntMember .................................................................................................................  183.1.11 AddJsonMember..............................................................................................................  183.1.12 AddNullMember ...............................................................................................................  183.1.13 AddObjectMember...........................................................................................................  183.1.14 AddStringMember............................................................................................................  193.1.15 AddUint64Member...........................................................................................................  193.1.16 AddUintMember...............................................................................................................  193.1.17 ArrayBegin .......................................................................................................................  203.1.18 ArrayEnd..........................................................................................................................  203.1.19 ClearArray........................................................................................................................  203.1.20 CopyDocument ................................................................................................................  213.1.21 CopyJson.........................................................................................................................  213.1.22 CopyString .......................................................................................................................  223.1.23 FindMember.....................................................................................................................  223.1.24 FindMemberPath .............................................................................................................  223.1.25 GetArraySize ...................................................................................................................  233.1.26 GetArrayValue .................................................................................................................  233.1.27 GetArrayValueByIdx ........................................................................................................  233.1.28 GetBase64.......................................................................................................................  233.1.29 GetBool............................................................................................................................  243.1.30 GetDateTime ...................................................................................................................  243.1.31 GetDcTime.......................................................................................................................  243.1.32 GetDocument...................................................................................................................  243.1.33 GetDocumentLength........................................................................................................  253.1.34 GetDocumentRoot ...........................................................................................................  253.1.35 GetDouble........................................................................................................................  253.1.36 GetFileTime .....................................................................................................................  253.1.37 GetHexBinary ..................................................................................................................  253.1.38 GetInt ...............................................................................................................................  26

Page 4: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE10004 Version: 1.7

3.1.39 GetInt64 ...........................................................................................................................  263.1.40 GetJson ...........................................................................................................................  263.1.41 GetJsonLength ................................................................................................................  263.1.42 GetMaxDecimalPlaces ....................................................................................................  273.1.43 GetMemberName ............................................................................................................  273.1.44 GetMemberValue.............................................................................................................  273.1.45 GetString..........................................................................................................................  273.1.46 GetStringLength...............................................................................................................  283.1.47 GetType ...........................................................................................................................  283.1.48 GetUint.............................................................................................................................  283.1.49 GetUint64.........................................................................................................................  283.1.50 HasMember .....................................................................................................................  293.1.51 IsArray .............................................................................................................................  293.1.52 IsBase64..........................................................................................................................  293.1.53 IsBool...............................................................................................................................  293.1.54 IsDouble...........................................................................................................................  303.1.55 IsFalse .............................................................................................................................  303.1.56 IsHexBinary .....................................................................................................................  303.1.57 IsInt ..................................................................................................................................  303.1.58 IsInt64 ..............................................................................................................................  303.1.59 IsISO8601TimeFormat ....................................................................................................  313.1.60 IsNull ................................................................................................................................  313.1.61 IsNumber .........................................................................................................................  313.1.62 IsObject............................................................................................................................  313.1.63 IsString.............................................................................................................................  313.1.64 IsTrue...............................................................................................................................  323.1.65 IsUint................................................................................................................................  323.1.66 IsUint64............................................................................................................................  323.1.67 LoadDocumentFromFile ..................................................................................................  323.1.68 MemberBegin ..................................................................................................................  333.1.69 MemberEnd .....................................................................................................................  333.1.70 NewDocument .................................................................................................................  333.1.71 NextArray.........................................................................................................................  333.1.72 ParseDocument ...............................................................................................................  333.1.73 PushbackBase64Value....................................................................................................  343.1.74 PushbackBoolValue.........................................................................................................  343.1.75 PushbackDateTimeValue ................................................................................................  343.1.76 PushbackDcTimeValue ...................................................................................................  353.1.77 PushbackDoubleValue ....................................................................................................  353.1.78 PushbackFileTimeValue ..................................................................................................  353.1.79 PushbackHexBinaryValue ...............................................................................................  353.1.80 PushbackInt64Value........................................................................................................  363.1.81 PushbackIntValue............................................................................................................  363.1.82 PushbackJsonValue ........................................................................................................  363.1.83 PushbackNullValue..........................................................................................................  363.1.84 PushbackStringValue ......................................................................................................  37

Page 5: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE1000 5Version: 1.7

3.1.85 PushbackUint64Value .....................................................................................................  373.1.86 PushbackUintValue .........................................................................................................  373.1.87 RemoveAllMembers ........................................................................................................  383.1.88 RemoveArray...................................................................................................................  383.1.89 RemoveMember ..............................................................................................................  383.1.90 RemoveMemberByName ................................................................................................  393.1.91 SaveDocumentToFile ......................................................................................................  393.1.92 SetArray...........................................................................................................................  393.1.93 SetBase64 .......................................................................................................................  403.1.94 SetBool ............................................................................................................................  403.1.95 SetDateTime....................................................................................................................  403.1.96 SetDcTime .......................................................................................................................  403.1.97 SetDouble ........................................................................................................................  413.1.98 SetFileTime......................................................................................................................  413.1.99 SetHexBinary...................................................................................................................  413.1.100 SetInt ...............................................................................................................................  423.1.101 SetInt64 ...........................................................................................................................  423.1.102 SetJson............................................................................................................................  423.1.103 SetMaxDecimalPlaces.....................................................................................................  423.1.104 SetNull .............................................................................................................................  433.1.105 SetObject .........................................................................................................................  433.1.106 SetString ..........................................................................................................................  433.1.107 SetUint .............................................................................................................................  433.1.108 SetUint64 .........................................................................................................................  44

3.2 FB_JsonDynDomParser .................................................................................................................. 443.3 FB_JsonSaxReader ........................................................................................................................ 44

3.3.1 DecodeBase64 ................................................................................................................  443.3.2 DecodeDateTime.............................................................................................................  453.3.3 DecodeDcTime ................................................................................................................  453.3.4 DecodeFileTime...............................................................................................................  453.3.5 DecodeHexBinary............................................................................................................  463.3.6 GetLastParseResult.........................................................................................................  463.3.7 IsBase64..........................................................................................................................  463.3.8 IsHexBinary .....................................................................................................................  463.3.9 IsISO8601TimeFormat ....................................................................................................  473.3.10 Parse ...............................................................................................................................  473.3.11 ParseValues ....................................................................................................................  47

3.4 FB_JsonSaxWriter........................................................................................................................... 473.4.1 AddBase64 ......................................................................................................................  473.4.2 AddBool ...........................................................................................................................  483.4.3 AddDateTime...................................................................................................................  483.4.4 AddDcTime ......................................................................................................................  483.4.5 AddDint ............................................................................................................................  483.4.6 AddFileTime.....................................................................................................................  493.4.7 AddHexBinary..................................................................................................................  493.4.8 AddKey ............................................................................................................................  49

Page 6: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE10006 Version: 1.7

3.4.9 AddKeyBool .....................................................................................................................  503.4.10 AddKeyDateTime.............................................................................................................  503.4.11 AddKeyDcTime................................................................................................................  503.4.12 AddKeyFileTime ..............................................................................................................  503.4.13 AddKeyLreal ....................................................................................................................  513.4.14 AddKeyNull ......................................................................................................................  513.4.15 AddKeyNumber ...............................................................................................................  513.4.16 AddKeyString...................................................................................................................  513.4.17 AddLint.............................................................................................................................  523.4.18 AddLreal ..........................................................................................................................  523.4.19 AddNull ............................................................................................................................  523.4.20 AddRawArray...................................................................................................................  523.4.21 AddRawObject.................................................................................................................  533.4.22 AddReal ...........................................................................................................................  533.4.23 AddString .........................................................................................................................  533.4.24 AddUdint ..........................................................................................................................  533.4.25 AddUlint ...........................................................................................................................  543.4.26 CopyDocument ................................................................................................................  543.4.27 EndArray..........................................................................................................................  543.4.28 EndObject ........................................................................................................................  543.4.29 GetDocument...................................................................................................................  553.4.30 GetDocumentLength........................................................................................................  553.4.31 GetMaxDecimalPlaces ....................................................................................................  553.4.32 ResetDocument ...............................................................................................................  553.4.33 SetMaxDecimalPlaces.....................................................................................................  553.4.34 StartArray.........................................................................................................................  553.4.35 StartObject.......................................................................................................................  56

3.5 FB_JsonReadWriteDataType.......................................................................................................... 563.5.1 AddJsonKeyPropertiesFromSymbol................................................................................  563.5.2 AddJsonKeyValueFromSymbol .......................................................................................  563.5.3 AddJsonValueFromSymbol .............................................................................................  573.5.4 CopyJsonStringFromSymbol ...........................................................................................  573.5.5 CopyJsonStringFromSymbolProperties...........................................................................  583.5.6 GetDataTypeNameByAddress ........................................................................................  583.5.7 GetJsonFromSymbol .......................................................................................................  583.5.8 GetJsonStringFromSymbol..............................................................................................  593.5.9 GetJsonStringFromSymbolProperties .............................................................................  593.5.10 GetSizeJsonStringFromSymbol.......................................................................................  603.5.11 GetSizeJsonStringFromSymbolProperties ......................................................................  603.5.12 GetSymbolNameByAddress ............................................................................................  603.5.13 SetSymbolFromJson .......................................................................................................  60

3.6 FB_XmlDomParser.......................................................................................................................... 613.6.1 AppendAttribute ...............................................................................................................  613.6.2 AppendAttributeAsBool....................................................................................................  613.6.3 AppendAttributeAsDouble ...............................................................................................  613.6.4 AppendAttributeAsFloat...................................................................................................  62

Page 7: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE1000 7Version: 1.7

3.6.5 AppendAttributeAsInt.......................................................................................................  623.6.6 AppendAttributeAsLint .....................................................................................................  623.6.7 AppendAttributeAsUint ....................................................................................................  633.6.8 AppendAttributeAsUlint....................................................................................................  633.6.9 AppendAttributeCopy.......................................................................................................  633.6.10 AppendChild ....................................................................................................................  643.6.11 AppendChildAsBool.........................................................................................................  643.6.12 AppendChildAsDouble.....................................................................................................  643.6.13 AppendChildAsFloat ........................................................................................................  653.6.14 AppendChildAsInt ............................................................................................................  653.6.15 AppendChildAsLint ..........................................................................................................  653.6.16 AppendChildAsUint..........................................................................................................  663.6.17 AppendChildAsUlint.........................................................................................................  663.6.18 AppendCopy ....................................................................................................................  663.6.19 AppendNode....................................................................................................................  673.6.20 Attributes..........................................................................................................................  673.6.21 AttributeAsBool ................................................................................................................  673.6.22 AttributeAsDouble............................................................................................................  683.6.23 AttributeAsFloat ...............................................................................................................  683.6.24 AttributeAsInt ...................................................................................................................  683.6.25 AttributeAsLint .................................................................................................................  683.6.26 AttributeAsUint.................................................................................................................  693.6.27 AttributeAsUlint ................................................................................................................  693.6.28 AttributeBegin ..................................................................................................................  693.6.29 AttributeFromIterator........................................................................................................  693.6.30 AttributeName..................................................................................................................  703.6.31 Attributes..........................................................................................................................  703.6.32 AttributeText ....................................................................................................................  703.6.33 Begin................................................................................................................................  703.6.34 BeginByName..................................................................................................................  713.6.35 Child.................................................................................................................................  713.6.36 ChildByAttribute ...............................................................................................................  713.6.37 ChildByAttributeAndName ...............................................................................................  723.6.38 ChildByName...................................................................................................................  723.6.39 Children ...........................................................................................................................  723.6.40 ChildrenByName..............................................................................................................  733.6.41 Compare ..........................................................................................................................  733.6.42 CopyAttributeText ............................................................................................................  733.6.43 CopyDocument ................................................................................................................  743.6.44 CopyNodeText.................................................................................................................  743.6.45 CopyNodeXml..................................................................................................................  743.6.46 FirstNodeByPath..............................................................................................................  753.6.47 GetAttributeTextLength....................................................................................................  753.6.48 GetDocumentLength........................................................................................................  753.6.49 GetDocumentNode ..........................................................................................................  753.6.50 GetNodeTextLength ........................................................................................................  76

Page 8: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE10008 Version: 1.7

3.6.51 GetNodeXmlLength .........................................................................................................  763.6.52 GetRootNode...................................................................................................................  763.6.53 InsertAttributeCopy ..........................................................................................................  763.6.54 InsertAttribute ..................................................................................................................  773.6.55 InsertChild........................................................................................................................  773.6.56 InsertCopy .......................................................................................................................  773.6.57 IsEnd................................................................................................................................  773.6.58 LoadDocumentFromFile ..................................................................................................  783.6.59 NewDocument .................................................................................................................  783.6.60 Next .................................................................................................................................  783.6.61 NextAttribute ....................................................................................................................  793.6.62 NextByName....................................................................................................................  793.6.63 NextSibling.......................................................................................................................  793.6.64 NextSiblingByName.........................................................................................................  793.6.65 Node ................................................................................................................................  803.6.66 NodeAsBool.....................................................................................................................  803.6.67 NodeAsDouble.................................................................................................................  803.6.68 NodeAsFloat ....................................................................................................................  803.6.69 NodeAsInt ........................................................................................................................  813.6.70 NodeAsLint ......................................................................................................................  813.6.71 NodeAsUint......................................................................................................................  813.6.72 NodeAsUlint.....................................................................................................................  813.6.73 NodeName.......................................................................................................................  823.6.74 NodeText .........................................................................................................................  823.6.75 ParseDocument ...............................................................................................................  823.6.76 RemoveChild ...................................................................................................................  823.6.77 RemoveChildByName .....................................................................................................  833.6.78 SaveDocumentToFile ......................................................................................................  833.6.79 SetAttribute ......................................................................................................................  833.6.80 SetAttributeAsBool...........................................................................................................  843.6.81 SetAttributeAsDouble ......................................................................................................  843.6.82 SetAttributeAsFloat..........................................................................................................  843.6.83 SetAttributeAsInt..............................................................................................................  843.6.84 SetAttributeAsLint ............................................................................................................  853.6.85 SetAttributeAsUint ...........................................................................................................  853.6.86 SetAttributeAsUlint...........................................................................................................  853.6.87 SetChild ...........................................................................................................................  853.6.88 SetChildAsBool................................................................................................................  863.6.89 SetChildAsDouble............................................................................................................  863.6.90 SetChildAsFloat ...............................................................................................................  863.6.91 SetChildAsInt ...................................................................................................................  863.6.92 SetChildAsLint .................................................................................................................  873.6.93 SetChildAsUint.................................................................................................................  873.6.94 SetChildAsUlint................................................................................................................  87

3.7 FB_JwtEncode ................................................................................................................................ 87

4 Interfaces.................................................................................................................................................. 89

Page 9: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE1000 9Version: 1.7

4.1 ITcJsonSaxHandler ......................................................................................................................... 894.1.1 OnBool.............................................................................................................................  894.1.2 OnDint..............................................................................................................................  894.1.3 OnEndArray .....................................................................................................................  894.1.4 OnEndObject ...................................................................................................................  894.1.5 OnKey..............................................................................................................................  894.1.6 OnLint ..............................................................................................................................  904.1.7 OnLreal ............................................................................................................................  904.1.8 OnNull ..............................................................................................................................  904.1.9 OnStartArray....................................................................................................................  904.1.10 OnStartObject ..................................................................................................................  904.1.11 OnString...........................................................................................................................  914.1.12 OnUdint............................................................................................................................  914.1.13 OnUlint.............................................................................................................................  91

4.2 ITcJsonSaxValues........................................................................................................................... 914.2.1 OnBoolValue....................................................................................................................  914.2.2 OnDintValue ....................................................................................................................  924.2.3 OnLintValue .....................................................................................................................  924.2.4 OnLrealValue...................................................................................................................  924.2.5 OnNullValue.....................................................................................................................  924.2.6 OnStringValue .................................................................................................................  924.2.7 OnUdintValue ..................................................................................................................  934.2.8 OnUlintValue....................................................................................................................  93

5 Samples.................................................................................................................................................... 945.1 Tc3JsonXmlSampleJsonDataType ................................................................................................. 945.2 Tc3JsonXmlSampleJsonSaxReader ............................................................................................... 955.3 Tc3JsonXmlSampleJsonSaxWriter ................................................................................................. 965.4 Tc3JsonXmlSampleJsonDomReader.............................................................................................. 975.5 Tc3JsonXmlSampleXmlDomReader ............................................................................................... 985.6 Tc3JsonXmlSampleXmlDomWriter ................................................................................................. 99

6 Support and Service.............................................................................................................................. 101

Page 10: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Table of contents

TE100010 Version: 1.7

Page 11: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Foreword

TE1000 11Version: 1.7

1 Foreword

1.1 Notes on the documentationThis description is only intended for the use of trained specialists in control and automation engineering whoare familiar with applicable national standards.It is essential that the documentation and the following notes and explanations are followed when installingand commissioning the components. It is the duty of the technical personnel to use the documentation published at the respective time of eachinstallation and commissioning.

The responsible staff must ensure that the application or use of the products described satisfy all therequirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly underdevelopment.We reserve the right to revise and change the documentation at any time and without prior announcement.No claims for the modification of products that have already been supplied may be made on the basis of thedata, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, EtherCAT G®, EtherCAT G10®, EtherCAT P®, Safety over EtherCAT®,TwinSAFE®, XFC®, XTS® and XPlanar® are registered trademarks of and licensed by Beckhoff AutomationGmbH.Other designations used in this publication may be trademarks whose use by third parties for their ownpurposes could violate the rights of the owners.

Patent Pending

The EtherCAT Technology is covered, including but not limited to the following patent applications andpatents:EP1590927, EP1789857, EP1456722, EP2137893, DE102015105702with corresponding applications or registrations in various other countries.

EtherCAT® is a registered trademark and patented technology, licensed by Beckhoff Automation GmbH,Germany

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.The reproduction, distribution and utilization of this document as well as the communication of its contents toothers without express authorization are prohibited.Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of apatent, utility model or design.

Page 12: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Foreword

TE100012 Version: 1.7

1.2 Safety instructions

Safety regulations

Please note the following safety instructions and explanations!Product-specific safety instructions can be found on following pages or in the areas mounting, wiring,commissioning etc.

Exclusion of liability

All the components are supplied in particular hardware and software configurations appropriate for theapplication. Modifications to hardware or software configurations other than those described in thedocumentation are not permitted, and nullify the liability of Beckhoff Automation GmbH & Co. KG.

Personnel qualification

This description is only intended for trained specialists in control, automation and drive engineering who arefamiliar with the applicable national standards.

Description of symbols

In this documentation the following symbols are used with an accompanying safety instruction or note. Thesafety instructions must be read carefully and followed without fail!

DANGERSerious risk of injury!Failure to follow the safety instructions associated with this symbol directly endangers the life and health ofpersons.

WARNINGRisk of injury!Failure to follow the safety instructions associated with this symbol endangers the life and health of per-sons.

CAUTIONPersonal injuries!Failure to follow the safety instructions associated with this symbol can lead to injuries to persons.

NOTEDamage to the environment or devicesFailure to follow the instructions associated with this symbol can lead to damage to the environment orequipment.

Tip or pointerThis symbol indicates information that contributes to better understanding.

Page 13: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Overview

TE1000 13Version: 1.7

2 OverviewWith the aid of the PLC library Tc3_JsonXml, SAX and DOM parser technologies can be used to create andnavigate through JSON and XML documents.

System requirements

Target System Win7, WES7, WEC7, Win10IPC or CX, (x86, x64, ARM)

Min. TwinCAT version 3.1.4022.0Min. TwinCAT level TC1200 TC3 PLC

SAX (simple API for XML)

SAX was originally developed for handling XML documents, but can also be used for other data formatssuch as JSON. A SAX parser treats the data to be read or written as a sequential data stream. Whenreading a data stream, defined callback methods are called, which then return the corresponding contents ofthe data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring(callback methods) are stateless, i.e. they are not dependent on the preceding events. The advantage of thisis that the XML document never has to be completely contained in the memory and the application can react"on the fly" via the callbacks.

DOM (Document Object Model)

DOM is a specification for accessing XML documents, but can also be used for other data formats such asHTML or JSON. The interface is based on a defined object model, whose validity is a prerequisite for correctuse. This object model represents a document, e.g. a JSON document, in the form of a tree structure in thememory, which can then be used to navigate through the document. DOM allows navigation between theindividual nodes, the creation, moving and deletion of nodes, and the reading, changing and deletion of nodecontents. When editing is finished a new JSON or XML document is generated from the finalized treestructure. The advantage here is that no own data housekeeping needs to be created with the read-in data,since the data exist in the DOM and can be continuously accessed.

JSON document

The following section shows a JSON document as an example:{  "VariableNameX": 0.0,  "VariableNameY": 0.0,  "VariableNameZ": 0.0}

Metadata

The Tc3_JsonXml library contains the function block FB_JsonReadWriteDataType [} 56], which enablesautomatic generation of metadata by means of PLC attributes.{  "Values": {    "VariableNameX": 0.0,    "VariableNameY": 0.0,    "VariableNameZ": 0.0  },  "MetaData": {    "VariableNameX": {      "Unit": "A"    },    "VariableNameY": {      "Unit": "V"    },    "VariableNameZ": {      "Unit": "mA"

Page 14: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Overview

TE100014 Version: 1.7

    }  }}

See also: Examples > Tc3JsonXmlSampleJsonDataType [} 94].

In order to use UTF-8 characters, e.g. in the automatic generation of metadata via the function blockFB_JsonReadWriteDataType [} 56], the check box for the support of UTF-8 in the symbolism must beactivated in the TwinCAT project. To do this, double-click on SYSTEM in the project tree, open the Settingstab and activate the corresponding check box.

JSON Web Token (JWT)

JSON Web Token (JWT) is an open standard (based on RFC 7519) that defines a compact and self-describing format for securely transmitting information between communication devices in the form of aJSON object. The authenticity of the transmitted information can be verified and ensured, since a JWT isprovided with a digital signature. The signature can involve a shared secret (via an HMAC algorithm) or apublic/private key (via RSA).

The most common application example for JWT is the authorization of a device or user for a service. Once auser has logged into the service, all further requests to the service include the JWT. Based on the JWT, theservice can then decide which additional services or resources the user may access. This means, forexample, that single sign-on solutions can be implemented in cloud services.

The Tc3_JsonXml library provides a function for creating a JWT via the FB_JwtEncode [} 87] method.

Page 15: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 15Version: 1.7

3 Function blocks

3.1 FB_JsonDomParserThis function block is derived from the same internal function block as FB_JsonDynDomParser [} 44] andthus offers the same interface.

The two derived function blocks differ only in their internal memory management. FB_JsonDomParser [} 15]is optimized for the fast and efficient parsing and creation of JSON documents that are only changed a little.It takes up less memory space than FB_DynDomParser [} 44] and is faster, but it consumes new memorywith each change (e.g. SetObject [} 43]). This allocated memory is only released again by calling themethod NewDocument [} 33].

3.1.1 AddArrayMemberThis method adds an array member to a JSON object.

SyntaxMETHOD AddArrayMember : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VARVAR_INPUT  reserve : UDINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.AddArrayMember(jsonDoc, 'TestArray', 0);

3.1.2 AddBase64MemberThis method adds a Base64 member to a JSON object. A structure, for example, can be addressed as aninput parameter. The corresponding Base64 coding is done by the method.

SyntaxMETHOD AddBase64Member : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonBase64 := fbJson.AddBase64Member(jsonDoc, 'TestBase64', ADR(stStruct), SIZEOF(stStruct));

3.1.3 AddBoolMemberThis method adds a Bool member to a JSON object.

Page 16: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100016 Version: 1.7

SyntaxMETHOD AddBoolMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : BOOL;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddBoolMember(jsonDoc, 'TestBool', TRUE);

3.1.4 AddDateTimeMemberThis method adds a DateTime member to a JSON object.

SyntaxMETHOD AddDateTimeMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DATE_AND_TIME;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddDateTimeMember(jsonDoc, 'TestDateTime', DT#2018-11-22-12:12);

3.1.5 AddDcTimeMemberThis method adds a DcTime member to a JSON object.

SyntaxMETHOD AddDcTimeMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DCTIME;END_VARVAR_IN_OUT CONSTANT    member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddDcTimeMember(jsonDoc, 'TestDcTime', 1234);

3.1.6 AddDoubleMemberThis method adds a Double member to a JSON object.

SyntaxMETHOD AddDoubleMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : LREAL;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Page 17: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 17Version: 1.7

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddDoubleMember(jsonDoc, 'TestDouble', 42.42);

3.1.7 AddFileTimeMemberThis method adds a FileTime member to a JSON object.

SyntaxMETHOD AddFileTimeMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : FILETIME;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddFileTimeMember(jsonDoc, 'TestFileTime', ftTime);

3.1.8 AddHexBinaryMemberThis method adds a HexBinary member to a JSON object.

SyntaxMETHOD AddHexBinaryMember : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddHexBinaryMember(jsonDoc, 'TestHexBinary', sHexBinary, SIZEOF(sHexBinary));

3.1.9 AddInt64MemberThis method adds an Int64 member to a JSON object.

SyntaxMETHOD AddFileTimeMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : LINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddInt64Member(jsonDoc, 'TestInt64', 42);

Page 18: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100018 Version: 1.7

3.1.10 AddIntMemberThis method adds an Int member to a JSON object.

SyntaxMETHOD AddIntMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddIntMember(jsonDoc, 'TestInt', 42);

3.1.11 AddJsonMemberThis method adds a JSON member to a JSON object.

SyntaxMETHOD AddJsonMember : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member  : STRING;  rawJson : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddJsonMember(jsonDoc, 'TestJson', sJson);

3.1.12 AddNullMemberThis method adds a NULL member to a JSON object.

SyntaxMETHOD AddNullMember : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddNullMember(jsonDoc, 'TestJson');

3.1.13 AddObjectMemberThis method adds an Object member to a JSON object.

SyntaxMETHOD AddObjectMember : SJsonValueVAR_INPUT v : SJsonValue;END_VAR

Page 19: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 19Version: 1.7

VAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddObjectMember(jsonDoc, 'TestObject');

3.1.14 AddStringMemberThis method adds a String member to a JSON object.

SyntaxMETHOD AddStringMember : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member : STRING;  value  : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddStringMember(jsonDoc, 'TestString', 'Test');

3.1.15 AddUint64MemberThis method adds an UInt64 member to a JSON object.

SyntaxMETHOD AddUint64Member : SJsonValueVAR_INPUT  v     : SJsonValue;  value : ULINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddUint64Member(jsonDoc, 'TestUint64', 42);

3.1.16 AddUintMemberThis method adds an UInt member to a JSON object.

SyntaxMETHOD AddUintMember : SJsonValueVAR_INPUT  v     : SJsonValue;  value : UDINT;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonMem := fbJson.AddUintMember(jsonDoc, 'TestUint', 42);

Page 20: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100020 Version: 1.7

3.1.17 ArrayBeginThis method returns the first element of an array and can be used together with the methods ArrayEnd() andNextArray() for iteration through a JSON array.

SyntaxMETHOD ArrayBegin : SJsonAIteratorVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonIterator := fbJson.ArrayBegin(jsonArray);jsonIteratorEnd := fbJson.ArrayEnd(jsonArray);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetArrayValue(jsonIterator);  jsonIterator := fbJson.NextArray(jsonIterator);END_WHILE

3.1.18 ArrayEndThis method returns the last element of an array and can be used together with the methods ArrayBegin()and NextArray() for iteration through a JSON array.

SyntaxMETHOD ArrayEnd : SJsonAIteratorVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonIterator := fbJson.ArrayBegin(jsonArray);jsonIteratorEnd := fbJson.ArrayEnd(jsonArray);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetArrayValue(jsonIterator);  jsonIterator := fbJson.NextArray(jsonIterator);END_WHILE

3.1.19 ClearArrayThis method deletes the content of an array.

SyntaxMETHOD ClearArray : BOOLVAR_INPUT  v : SJsonValue;  i : SJsonAIterator;END_VAR

Sample call:

The following JSON document is to be loaded into the DOM memory:sMessage := '{"serialNumber":"123","batteryVoltage":"1547mV","clickType":"SINGLE", "array":["Hello",2,3]}';

The values of the JSON array "array" are to be deleted. First of all, the JSON document is searchediteratively for the "array" property, after which all elements of the array are deleted by calling the ClearArray()method.jsonDoc := fbJson.ParseDocument(sMessage);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonValue := fbJson.GetMemberValue(jsonIterator);

Page 21: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 21Version: 1.7

  IF sName = 'array' THEN    jsonArrayIterator := fbJson.ArrayBegin(jsonValue);    fbJson.ClearArray(jsonValue, jsonArrayIterator);  END_IF  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.20 CopyDocumentThis method copies the contents of the DOM memory into a variable of data type STRING, which can haveany length. The method returns the length of the string (including null termination). If the target buffer is toosmall, it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyDocument : UDINTVAR_INPUT  nDoc : DINT;END_VARVAR_IN_OUT CONSTANT  pDoc : STRING;END_VAR

Sample call:nLen := fbJson.CopyDocument(sJson, SIZEOF(sJson));

3.1.21 CopyJsonThis method extracts a JSON object from a key and stores it in a variable of data type STRING. ThisSTRING can be of any length. The method returns the length of the copied JSON object (including nulltermination). If the target buffer is too small, it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyJson : UDINTVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  pDoc : STRING;  nDoc : UDINT;END_VAR

Sample call:

The following JSON document is to be loaded into the DOM memory:sMessage := ' {"serialNumber":"123","meta":{"batteryVoltage":"1547mV","clickType":"SINGLE"}}';

The value of the JSON object "meta" is to be extracted and stored in a variable of data type STRING. Firstthe JSON document is searched iteratively for the property "meta", then its value or sub-object is extractedby calling the method CopyJson().jsonDoc := fbJson.ParseDocument(sMessage);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonValue := fbJson.GetMemberValue(jsonIterator);  IF sName = 'meta' THEN    fbJson.CopyJson(jsonValue, sString, SIZEOF(sString));  END_IF  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

After this run, the sString variable has the following content:{"batteryVoltage":"1547mV","clickType":"SINGLE"}

Page 22: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100022 Version: 1.7

3.1.22 CopyStringThis method copies the value of a key into a variable of the data type STRING, which can be of any length.The method returns the length of the copied string (including null termination). If the target buffer is too small,it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyString : UDINTVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  pStr : STRING;  nStr : UDINT;END_VAR

Sample call:

The following JSON document is to be loaded into the DOM memory:sMessage := ' {"serialNumber":"123","batteryVoltage":"1547mV","clickType":"SINGLE"}';

The value of the key "clickType" is to be extracted and stored in a variable of data type STRING. First, theJSON document is iteratively searched for the property "clickType".jsonDoc := fbJson.ParseDocument(sMessage);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonValue := fbJson.GetMemberValue(jsonIterator);  IF sName = 'clickType' THEN    fbJson.CopyString(jsonValue, sString, SIZEOF(sString));  END_IF  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

After this run, the sString variable has the following content:SINGLE

3.1.23 FindMemberThis method searches for a specific property in a JSON document and returns it. 0 is returned if nocorresponding property is found.

SyntaxMETHOD FindMember : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonProp := fbJson.FindMember(jsonDoc, 'PropertyName');

3.1.24 FindMemberPathThis method searches for a specific property in a JSON document and returns it. The property is specifiedaccording to its path in the document. 0 is returned if no corresponding property is found.

SyntaxMETHOD FindMemberPath : SJsonValueVAR_INPUT  v : SJsonValue

Page 23: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 23Version: 1.7

END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMemberPath(jsonDoc, sPath);

3.1.25 GetArraySizeThis method returns the number of elements in a JSON array.

SyntaxMETHOD GetArraySize : UDINTVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');nSize := fbJson.GetArraySize(jsonArray);

3.1.26 GetArrayValueThis method returns the value at the current iterator position of an array.

SyntaxMETHOD GetArrayValue : SJsonValueVAR_INPUT  i : SJsonAIterator;END_VAR

Sample call:jsonIterator := fbJson.ArrayBegin(jsonArray);jsonIteratorEnd := fbJson.ArrayEnd(jsonArray);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetArrayValue(jsonIterator);  jsonIterator := fbJson.NextArray(jsonIterator);END_WHILE

3.1.27 GetArrayValueByIdxThis method returns the value of an array in a specified index.

SyntaxMETHOD GetArrayValueByIdx : SJsonValueVAR_INPUT  v : SJsonValue;  idx : UDINT;END_VAR

Sample call:jsonValue := fbJson.GetArrayValueByIdx(jsonArray, 1);

3.1.28 GetBase64This method decodes a Base64 value from a JSON property. If the content of a data structure, for example,is located behind the Base64 value, the decoded content can also be placed on an identical structure again.

Page 24: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100024 Version: 1.7

SyntaxMETHOD GetBase64 : DINTVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonBase64 := fbJson.FindMember(jsonDoc, 'base64');nSize := fbJson.GetBase64(jsonBase64, ADR(stStruct), SIZEOF(stStruct));

3.1.29 GetBoolThis method returns the value of a property of the data type BOOL.

SyntaxMETHOD GetBool : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.30 GetDateTimeThis method returns the value of a property of the data type DATE_AND_TIME.

SyntaxMETHOD GetDateTime : DATE_AND_TIMEVAR_INPUT  v : SJsonValue;END_VAR

3.1.31 GetDcTimeThis method returns the value of a property of the data type DCTIME.

SyntaxMETHOD GetDcTime : DCTIMEVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');dcTime := fbJson.GetDcTime(jsonProp);

3.1.32 GetDocumentThis method returns the content of the DOM memory as the data type STRING(255). With longer strings, themethod will return a NULL string. In this case the method CopyDocument [} 21]() must be used.

SyntaxMETHOD GetDocument : STRING(255)

Sample call:sJson := fbJson.GetDocument();

Page 25: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 25Version: 1.7

3.1.33 GetDocumentLengthThis method returns the length of a JSON document in the DOM memory.

SyntaxMETHOD GetDocumentLength: UDINT

Sample call:nLen := fbJson.GetDocumentLength();

3.1.34 GetDocumentRootThis method returns the root node of a JSON document in the DOM memory.

SyntaxMETHOD GetDocumentRoot : SJsonValue

Sample call:jsonRoot := fbJson.GetDocumentRoot();

3.1.35 GetDoubleThis method returns the value of a property of the data type LREAL.

SyntaxMETHOD GetDouble : LREALVAR_INPUT  v : SJsonValue;END_VAR

3.1.36 GetFileTimeThis method returns the value of a property of the data type DCTIME.

SyntaxMETHOD GetFileTime : FILETIMEVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');fileTime := fbJson.GetFileTime(jsonProp);

3.1.37 GetHexBinaryThis method decodes the HexBinary content of a property and writes it to a certain memory address, e.g. toa data structure.

SyntaxMETHOD GetHexBinary : DINTVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Page 26: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100026 Version: 1.7

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');nLen := fbJson.GetHexBinary(jsonProp, ADR(stStruct), SIZEOF(stStruct));

3.1.38 GetIntThis method returns the value of a property of the data type DINT.

SyntaxMETHOD GetInt : DINTVAR_INPUT  v : SJsonValue;END_VAR

3.1.39 GetInt64This method returns the value of a property of the data type LINT.

SyntaxMETHOD GetInt64 : LINTVAR_INPUT  v : SJsonValue;END_VAR

3.1.40 GetJsonThis method returns the value of a property as data type STRING(255), if this is a JSON document itself.With longer strings, the method will return a NULL string. In this case the method CopyJson [} 21]() must beused.

SyntaxMETHOD GetJson : STRING(255)VAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');sJson := fbJson.GetJson(jsonProp);

3.1.41 GetJsonLengthThis method returns the length of a property if this is a JSON document.

SyntaxMETHOD GetJsonLength : UDINTVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');nLen := fbJson.GetJsonLength(jsonProp);

Page 27: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 27Version: 1.7

3.1.42 GetMaxDecimalPlacesThis method returns the current setting for MaxDecimalPlaces. This influences the number of decimal placesin the case of floating point numbers.

SyntaxMETHOD GetMaxDecimalPlaces : DINT

Sample call:nDec := fbJson.GetMaxDecimalPlaces();

3.1.43 GetMemberNameThis method returns the name of a JSON property member at the position of the current iterator, e.g. duringthe iteration of a child element of a JSON property with the methods MemberBegin(), MemberEnd() andNextMember().

SyntaxMETHOD GetMemberName : STRINGVAR_INPUT  i : SJsonIterator;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.44 GetMemberValueThis method returns the value of a JSON property member at the position of the current iterator, e.g. duringthe iteration of a child element of a JSON property with the methods MemberBegin(), MemberEnd() andNextMember().

SyntaxMETHOD GetMemberValue : SJsonValueVAR_INPUT  i : SJsonIterator;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  jsonValue := fbJson.GetMemberValue(jsonIterator);  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.45 GetStringThis method returns the value of a property of the data type STRING(255). With longer strings, the methodwill return a NULL string. In this case the method CopyString [} 22]() must be used.

Page 28: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100028 Version: 1.7

SyntaxMETHOD GetString : STRING(255)VAR_INPUT  v : SJsonValue;END_VAR

3.1.46 GetStringLengthThis method returns the length of a property if its value is a string.

SyntaxMETHOD GetStringLength : UDINTVAR_INPUT  v : SJsonValueEND_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');nLen := fbJson.GetStringLength(jsonProp);

3.1.47 GetTypeThis method returns the type of a property value. The return value can assume one of the values of theenum EJsonType.

SyntaxMETHOD GetStringLength : EJsonTypeVAR_INPUT  v : SJsonValueEND_VAR

TYPE EJsonType :(  eNullType := 0,  eFalseType := 1,  eTrueType := 2,  eObjectType := 3,  eArrayType := 4,  eStringType := 5,  eNumberType := 6) DINT;

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');eJsonType := fbJson.GetType(jsonProp);

3.1.48 GetUintThis method returns the value of a property of the data type UDINT.

SyntaxMETHOD GetUint : UDINTVAR_INPUT  v : SJsonValue;END_VAR

3.1.49 GetUint64This method returns the value of a property of the data type ULINT.

Page 29: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 29Version: 1.7

SyntaxMETHOD GetUint64 : ULINTVAR_INPUT  v : SJsonValue;END_VAR

3.1.50 HasMemberThis method checks whether a certain property is present in the DOM memory. If the property is present themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD HasMember : BOOLVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  member : STRING;END_VAR

Sample call:bHasMember := fbJson.HasMember(jsonDoc, 'PropertyName');

3.1.51 IsArrayThis method checks whether a given property is an array. If that is the case, the method returns TRUE,otherwise it returns FALSE.

SyntaxMETHOD IsArray : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.52 IsBase64This method checks whether the value of a given property is of the data type Base64. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsBase64 : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.53 IsBoolThis method checks whether the value of a given property is of the data type BOOL. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsBool : BOOLVAR_INPUT  v : SJsonValue;END_VAR

Page 30: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100030 Version: 1.7

3.1.54 IsDoubleThis method checks whether the value of a given property is of the data type Double (PLC: LREAL). If that isthe case, the method returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsDouble : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.55 IsFalseThis method checks whether the value of a given property is FALSE. If that is the case, the method returnsTRUE, otherwise it returns FALSE.

SyntaxMETHOD IsFalse : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.56 IsHexBinaryThis method checks whether the value of a property is in the HexBinary format. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsHexBinary: BOOLVAR_INPUT  v : SJsonValueEND_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');bRet := fbJson.IsHexBinary(jsonProp);

3.1.57 IsIntThis method checks whether the value of a given property is of the data type Integer (PLC: DINT). If that isthe case, the method returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsInt : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.58 IsInt64This method checks whether the value of a given property is of the data type LINT. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

Page 31: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 31Version: 1.7

SyntaxMETHOD IsInt64 : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.59 IsISO8601TimeFormatThis method checks whether the value of a given property has a time format according to ISO8601. If that isthe case, the method returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsISO8601TimeFormat : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.60 IsNullThis method checks whether the value of a given property is NULL. If that is the case, the method returnsTRUE, otherwise it returns FALSE.

SyntaxMETHOD IsNull : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.61 IsNumberThis method checks whether the value of a given property is a numerical value. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsNumber : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.62 IsObjectThis method checks whether the given property is a further JSON object. If that is the case, the methodreturns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsObject : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.63 IsStringThis method checks whether the value of a given property is of the data type STRING. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

Page 32: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100032 Version: 1.7

SyntaxMETHOD IsString : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.64 IsTrueThis method checks whether the value of a given property is TRUE. If that is the case, the method returnsTRUE, otherwise it returns FALSE.

SyntaxMETHOD IsTrue : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.65 IsUintThis method checks whether the value of a given property is of the data type UDINT. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsUint : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.66 IsUint64This method checks whether the value of a given property is of the data type ULINT. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsUint64 : BOOLVAR_INPUT  v : SJsonValue;END_VAR

3.1.67 LoadDocumentFromFileThis method loads a JSON document from a file. A rising edge on the input parameter bExec triggers theloading procedure. Following the successful loading of a file, the return value of the method jumps to TRUEfor one cycle and is then automatically reset by the driver.

SyntaxMETHOD LoadDocumentFromFile : BOOLVAR_INPUT  bExec : BOOL;END_VARVAR_IN_OUT CONSTANT  sFile : STRING;END_VAR

Sample call:bLoaded := fbJson.LoadDocumentFromFile(sFile, bLoad);

Page 33: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 33Version: 1.7

3.1.68 MemberBeginThis method returns the first child element below a JSON property and can be used by a JSON propertytogether with the methods MemberEnd() and NextMember() for iteration.

SyntaxMETHOD MemberBegin : SJsonIteratorVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.69 MemberEndThis method returns the last child element below a JSON property and can be used by a JSON propertytogether with the methods MemberBegin() and NextMember() for iteration.

SyntaxMETHOD MemberEnd : SJsonIteratorVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.70 NewDocumentThis method generates a new empty JSON document in the DOM memory.

SyntaxMETHOD NewDocument : SJsonValue

Sample call:jsonDoc := fbJson.NewDocument();

3.1.71 NextArray

3.1.72 ParseDocumentThis method loads a JSON object into the DOM memory for further processing. The JSON object takes theform of a string and is transferred to the method as an input. A reference to the JSON document in the DOMmemory is returned to the caller.

Page 34: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100034 Version: 1.7

SyntaxMETHOD ParseDocument : SJsonValueVAR_IN_OUT CONSTANT  sJson : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sJsonString);

3.1.73 PushbackBase64ValueThis method appends a Base64 value to the end of an array. A structure, for example, can be addressed asan input parameter. The corresponding Base64 coding is done by the method.

SyntaxMETHOD PushbackBase64Value : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackBase64Value(jsonArray, ADR(stStruct), SIZEOF(stStruct));

3.1.74 PushbackBoolValueThis method appends a value of the data type BOOL to the end of an array.

SyntaxMETHOD PushbackBoolValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : BOOL;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackBoolValue(jsonArray, TRUE);

3.1.75 PushbackDateTimeValueThis method appends a value of the data type DATE_AND_TIME to the end of an array.

SyntaxMETHOD PushbackDateTimeValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DATE_AND_TIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackDateTimeValue(jsonArray, dtTime);

Page 35: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 35Version: 1.7

3.1.76 PushbackDcTimeValueThis method appends a value of the data type DCTIME to the end of an array.

SyntaxMETHOD PushbackDcTimeValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DCTIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackDcTimeValue(jsonArray, dcTime);

3.1.77 PushbackDoubleValueThis method appends a value of the data type Double to the end of an array.

SyntaxMETHOD PushbackDoubleValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : LREAL;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackDoubleValue(jsonArray, 42.42);

3.1.78 PushbackFileTimeValueThis method appends a value of the data type FILETIME to the end of an array.

SyntaxMETHOD PushbackFileTimeValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : FILETIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackFileTimeValue(jsonArray, fileTime);

3.1.79 PushbackHexBinaryValueThis method appends a HexBinary value to the end of an array. The coding in the HexBinary format isexecuted by the method. A data structure, for example, can be used as the source.

SyntaxMETHOD PushbackHexBinaryValue : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Page 36: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100036 Version: 1.7

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackHexBinaryValue(jsonArray, ADR(stStruct), SIZEOF(stStruct));

3.1.80 PushbackInt64ValueThis method appends a value of the data type Int64 to the end of an array.

SyntaxMETHOD PushbackInt64Value : SJsonValueVAR_INPUT  v : SJsonValue;  value : LINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackInt64Value(jsonArray, 42);

3.1.81 PushbackIntValueThis method appends a value of the data type INT to the end of an array.

SyntaxMETHOD PushbackIntValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackIntValue(jsonArray, 42);

3.1.82 PushbackJsonValueThis method appends a JSON document to the end of an array.

SyntaxMETHOD PushbackJsonValue : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  rawJson : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackJsonValue(jsonArray, sJson);

3.1.83 PushbackNullValueThis method appends a NULL value to the end of an array.

Page 37: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 37Version: 1.7

SyntaxMETHOD PushbackNullValue : SJsonValueVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackNullValue(jsonArray);

3.1.84 PushbackStringValueThis method appends a value of the data type DCTIME to the end of an array.

SyntaxMETHOD PushbackStringValue : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  value : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackStringValue(jsonArray, sString);

3.1.85 PushbackUint64ValueThis method appends a value of the data type UInt64 to the end of an array.

SyntaxMETHOD PushbackUint64Value : SJsonValueVAR_INPUT  v     : SJsonValue;  value : ULINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackUint64Value(jsonArray, 42);

3.1.86 PushbackUintValueThis method appends a value of the data type UInt to the end of an array.

SyntaxMETHOD PushbackUintValue : SJsonValueVAR_INPUT  v     : SJsonValue;  value : UDINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonArray := fbJson.FindMember(jsonDoc, 'array');jsonValue := fbJson.PushbackUintValue(jsonArray, 42);

Page 38: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100038 Version: 1.7

3.1.87 RemoveAllMembersThis method removes all child elements from a given property.

SyntaxMETHOD RemoveAllMembers : BOOLVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');bRemoved := fbJson.RemoveAllMembers(jsonProp);

3.1.88 RemoveArrayThis method deletes the value of the current array iterator.

SyntaxMETHOD RemoveArray : BOOLVAR_INPUT  v : SJsonValue;  i : SJsonAIterator;END_VAR

Sample call:

The following JSON document is to be loaded into the DOM memory:sMessage := '{"serialNumber":"123","batteryVoltage":"1547mV","clickType":"SINGLE", "array":["Hello",2,3]}';

The first array position is to be deleted. First of all, the JSON document is searched iteratively for the "array"property, after which the first element of the array is removed by calling the RemoveArray() method.jsonDoc := fbJson.ParseDocument(sMessage);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  jsonValue := fbJson.GetMemberValue(jsonIterator);  IF sName = 'array' THEN    jsonArrayIterator := fbJson.ArrayBegin(jsonValue);    fbJson.RemoveArray(jsonValue, jsonArrayIterator);  END_IF  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.89 RemoveMemberThis method deletes the property at the current iterator.

SyntaxMETHOD RemoveMember : BOOLVAR_INPUT  v : SJsonValue;  i : SJsonIterator;  keepOrder : BOOL;END_VAR

Sample call:

The following JSON document is to be loaded into the DOM memory:sMessage := '{"serialNumber":"123","batteryVoltage":"1547mV","clickType":"SINGLE", "array":["Hello",2,3]}';

Page 39: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 39Version: 1.7

The "array" property is to be deleted. First of all, the JSON document is searched for the "array" property,after which the property is removed.jsonDoc := fbJson.ParseDocument(sMessage);jsonIterator := fbJson.MemberBegin(jsonDoc);jsonIteratorEnd := fbJson.MemberEnd(jsonDoc);WHILE jsonIterator <> jsonIteratorEnd DO  sName := fbJson.GetMemberName(jsonIterator);  IF sName = 'array' THEN    fbJson.RemoveMember(jsonDoc, jsonIterator);  END_IF  jsonIterator := fbJson.NextMember(jsonIterator);END_WHILE

3.1.90 RemoveMemberByNameThis method removes a child element from a given property. The element is referenced by its name.

SyntaxMETHOD RemoveMemberByName : BOOLVAR_INPUT  v         : SJsonValue;  keepOrder : BOOL;END_VARVAR_IN_OUT CONSTANT    member : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.RemoveMemberByName(jsonProp, 'ChildName');

3.1.91 SaveDocumentToFileThis method saves a JSON document in a file. A rising edge at the input parameter bExec triggers thesaving procedure. Following the successful saving of a file, the return value of the method jumps to TRUE forone cycle and is then automatically reset by the driver.

SyntaxMETHOD SaveDocumentToFile : BOOLVAR_INPUT    bExec : REFERENCE TO BOOL;END_VARVAR_IN_OUT CONSTANT    sFile : STRING;END_VAR

Sample call:bSaved := fbJson.SaveDocumentToFile(sFile, bSave);

3.1.92 SetArrayThis method sets the value of a property to the type "Array". New values can now be added to the array withthe Pushback methods.

SyntaxMETHOD SetArray : SJsonValueVAR_INPUT  v : SJsonValue;END_VAR

Sample call:

Page 40: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100040 Version: 1.7

jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetArray(jsonProp);

3.1.93 SetBase64This method sets the value of a property to a Base64-coded value. A data structure, for example, can beused as the source. Coding to the Base64 format takes place inside the method.

SyntaxMETHOD SetBase64 : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetBase64(jsonProp, ADR(stStruct), SIZEOF(stStruct));

3.1.94 SetBoolThis method sets the value of a property to a value of the data type BOOL.

SyntaxMETHOD SetBool : SJsonValueVAR_INPUT  v     : SJsonValue;  value : BOOL;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetBool(jsonProp, TRUE);

3.1.95 SetDateTimeThis method sets the value of a property to a value of the data type DATE_AND_TIME.

SyntaxMETHOD SetDateTime : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DATE_AND_TIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetDateTime(jsonProp, dtTime);

3.1.96 SetDcTimeThis method sets the value of a property to a value of the data type DCTIME.

Page 41: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 41Version: 1.7

SyntaxMETHOD SetDcTime : SJsonValueVAR_INPUT  v     : SJsonValue;  value : DCTIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetDcTime(jsonProp, dcTime);

3.1.97 SetDoubleThis method sets the value of a property to a value of the data type Double.

SyntaxMETHOD SetDouble : SJsonValueVAR_INPUT  v     : SJsonValue;  value : LREAL;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetDouble(jsonProp, 42.42);

3.1.98 SetFileTimeThis method sets the value of a property to a value of the data type FILETIME.

SyntaxMETHOD SetFileTime : SJsonValueVAR_INPUT  v     : SJsonValue;  value : FILETIME;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetFileTime(jsonProp, fileTime);

3.1.99 SetHexBinaryThis method sets the value of a property to a HexBinary-coded value. A data structure, for example, can beused as the source. Coding to the HexBinary format takes place inside the method.

SyntaxMETHOD SetHexBinary : SJsonValueVAR_INPUT  v : SJsonValue;  p : PVOID;  n : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetHexBinary(jsonProp, ADR(stStruct), SIZEOF(stStruct));

Page 42: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100042 Version: 1.7

3.1.100 SetIntThis method sets the value of a property to a value of the data type INT.

SyntaxMETHOD SetInt : SJsonValueVAR_INPUT  v : SJsonValue;  value : DINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetInt(jsonProp, 42);

3.1.101 SetInt64This method sets the value of a property to a value of the data type Int64.

SyntaxMETHOD SetInt64 : SJsonValueVAR_INPUT  v : SJsonValue;  value : LINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetInt64(jsonProp, 42);

3.1.102 SetJsonThis method inserts a further JSON document into the value of a property.

SyntaxMETHOD SetJson : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  rawJson : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetJson(jsonProp, sJson);

3.1.103 SetMaxDecimalPlacesThis method sets the current setting for MaxDecimalPlaces. This sets the maximum number of decimalplaces to be used with floating point numbers.

SyntaxMETHOD SetMaxDecimalPlacesVAR_INPUT  dp : DINT;END_VAR

Page 43: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 43Version: 1.7

Sample call:nDec := fbJson.SetMaxDecimalPlaces();

3.1.104 SetNullThis method sets the value of a property to the value NULL.

SyntaxMETHOD SetNull : SJsonValueVAR_INPUT  v : SJsonValue;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetNull(jsonProp);

3.1.105 SetObjectThis method sets the value of a property to the type "Object". This enables the nesting of JSON documents.

SyntaxMETHOD SetDouble : SJsonValueVAR_INPUT  v : SJsonValue;  value : LREAL;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetObject(jsonProp);

3.1.106 SetStringThis method sets the value of a property to a value of the data type STRING.

SyntaxMETHOD SetString : SJsonValueVAR_INPUT  v : SJsonValue;END_VARVAR_IN_OUT CONSTANT  value : STRING;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetString(jsonProp, 'Hello World');

3.1.107 SetUintThis method sets the value of a property to a value of the data type UInt.

Page 44: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100044 Version: 1.7

SyntaxMETHOD SetUint : SJsonValueVAR_INPUT  v     : SJsonValue;  value : UDINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetUint(jsonProp, 42);

3.1.108 SetUint64This method sets the value of a property to a value of the data type UInt64.

SyntaxMETHOD SetUint64 : SJsonValueVAR_INPUT  v     : SJsonValue;  value : ULINT;END_VAR

Sample call:jsonDoc := fbJson.ParseDocument(sExistingJsonDocument);jsonProp := fbJson.FindMember(jsonDoc, 'property');jsonValue := fbJson.SetUint64(jsonProp, 42);

3.2 FB_JsonDynDomParserThis function block is derived from the same internal function block as FB_JsonDomParser [} 15] and thusoffers the same interface.

The two derived function blocks differ only in their internal memory management. FB_JsonDynDomParser isoptimized for JSON documents to which many changes are made. It releases the allocated memory againafter the execution of an action (e.g. SetObject [} 43]).

Requirements

TwinCAT version Hardware Libraries to be integratedTwinCAT 3.1, Build 4024.7 x86, x64, ARM Tc3_JsonXml 3.3.8.0

3.3 FB_JsonSaxReader

3.3.1 DecodeBase64This method converts a Base64-formated string to binary data. If the conversion was successful the methodreturns TRUE, otherwise it returns FALSE.

SyntaxMETHOD DecodeBase64 : BOOLVAR_INPUT  sBase64 : STRING;  pBytes  : POINTER TO BYTE;  nBytes  : REFERENCE TO DINT;END_VAR

Sample call:

Page 45: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 45Version: 1.7

bSuccess := fbJson.DecodeBase64('SGVsbG8gVHdpbkNBVA==', ADR(byteArray), byteArraySize);

3.3.2 DecodeDateTimeThis method enables the generation of a PLC variable of the type DATE_AND_TIME or DT from astandardized ISO8601 time format (e.g. YYYY-MM-DDThh:mm:ss). DT corresponds to the number ofseconds starting from the date 01/01/1970. If the conversion was successful the method returns TRUE,otherwise it returns FALSE.

SyntaxMETHOD DecodeDateTime : BOOLVAR_IN_OUT CONSTANT  sDT : STRING;END_VARVAR_OUTPUT  nDT : DATE_AND_TIME;END_VAR

Sample call:bSuccess := fbJson.DecodeDateTime('2017-08-09T06:54:00', nDT => dateTime);

3.3.3 DecodeDcTimeThis method enables the generation of a PLC variable of the type DCTIME from a standardized ISO8601time format (e.g. YYYY-MM-DDThh:mm:ss). DCTIME corresponds to the number of nanoseconds startingfrom the date 01/01/2000. If the conversion was successful the method returns TRUE, otherwise it returnsFALSE.

SyntaxMETHOD DecodeDcTime : BOOLVAR_IN_OUT CONSTANT  sDC : STRING;END_VARVAR_OUTPUT  nDC : DCTIME;END_VAR

Sample call:bSuccess := fbJson.DecodeDcTime('2017-08-09T06:54:00', nDc => dcTime);

3.3.4 DecodeFileTimeThis method enables the generation of a PLC variable of the type FILETIME from a standardized ISO8601time format (e.g. YYYY-MM-DDThh:mm:ss). FILETIME corresponds to the number of nanoseconds startingfrom the date 01/01/1601 – measured in 100 nanoseconds. If the conversion was successful the methodreturns TRUE, otherwise it returns FALSE.

SyntaxMETHOD DecodeDateTime : BOOLVAR_IN_OUT CONSTANT  sFT : STRING;END_VARVAR_OUTPUT  nFT : FILETIME;END_VAR

Sample call:bSuccess := fbJson.DecodeFileTime('2017-08-09T06:54:00', nFT => fileTime);

Page 46: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100046 Version: 1.7

3.3.5 DecodeHexBinaryThis method converts a string containing hexadecimal values into binary data. If the conversion wassuccessful the method returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD DecodeHexBinary : BOOLVAR_IN_OUT CONSTANT  sHex : STRING;END_VARVAR_INPUT  pBytes : POINTER TO BYTE;  nBytes : REFERENCE TO DINT;END_VAR

Sample call:bSuccess := fbJson.DecodeHexBinary('ABCEF93A', ADR(byteArray), byteArraySize);

3.3.6 GetLastParseResult

SyntaxMETHOD GetLastParseResult : BOOL;VAR_INPUT  pOffset : POINTER TO LINT;  pError  : POINTER TO DINT;END_VAR

3.3.7 IsBase64This method checks whether the transferred string corresponds to the Base64 format. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsBase64 : BOOLVAR_IN_OUT CONSTANT  sBase64 : STRING;END_VAR

Sample call:bIsBase64 := fbJson.IsBase64('SGVsbG8gVHdpbkNBVA==');

3.3.8 IsHexBinaryThis method checks whether the transferred string consists of hexadecimal values. If that is the case, themethod returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsHexBinary : BOOLVAR_IN_OUT CONSTANT  sHex : STRING;END_VAR

Sample call:bSuccess := fbJson.IsHexBinary('ABCEF93A');

Page 47: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 47Version: 1.7

3.3.9 IsISO8601TimeFormatThis method checks whether the transferred string corresponds to the standardized ISO8601 time format. Ifthat is the case, the method returns TRUE, otherwise it returns FALSE.

SyntaxMETHOD IsISO8601TimeFormat : BOOLVAR_IN_OUT CONSTANT  sDT : STRING;END_VAR

Sample call:bSuccess := fbJson.IsISO8601TimeFormat('2017-08-09T06:54:00');

3.3.10 ParseThis method starts the SAX reader parsing procedure. The JSON object to be parsed and a reference to afunction block, which was derived from the interface ITcJsonSaxHandler, are transferred as inputparameters. This function block is then used for the callback methods of the SAX reader.

SyntaxMETHOD Parse : BOOLVAR_IN_OUT CONSTANT  sJson : STRING;END_VARVAR_INPUT  ipHdl : ITcJsonSaxHandler;END_VAR

3.3.11 ParseValuesThis method starts the SAX reader parsing procedure. The JSON object to be parsed and a reference to afunction block, which was derived from the interface ITcJsonSaxValues, are transferred as input parameters.This function block is then used for the callback methods of the SAX reader. What is special about thismethod is that exclusively values are taken into account in the callback methods, i.e. there are no OnKey() orOnStartObject() callbacks.

SyntaxMETHOD ParseValues : BOOLVAR_IN_OUT CONSTANT  sJson : STRING;END_VARVAR_INPUT  ipHdl : ITcJsonSaxValues;END_VAR

3.4 FB_JsonSaxWriter

3.4.1 AddBase64This method adds a value of the data type Base64 to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

Page 48: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100048 Version: 1.7

SyntaxMETHOD AddBase64VAR_INPUT  pBytes : Pointer TO BYTE;  nBytes : DINT;END_VAR

3.4.2 AddBoolThis method adds a value of the data type BOOL to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddBoolVAR_INPUT  value : BOOL;END_VAR

Sample call:fbJson.AddKey('bSwitch');fbJson.AddBool(TRUE);

3.4.3 AddDateTimeThis method adds a value of the data type DATE_AND_TIME to a property. Usually, a correspondingproperty was created beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddDateTimeVAR_INPUT  value : DATE_AND_TIME;END_VAR

Sample call:fbJson.AddKey('Timestamp');fbJson.AddDateTime(dtTime); // dtTime is of type DATE_AND_TIME

3.4.4 AddDcTimeThis method adds a value of the data type DCTIME to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddDcTimeVAR_INPUT  value : DCTIME;END_VAR

Sample call:fbJson.AddKey('Timestamp');fbJson.AddDcTime(dcTime); // dcTime is of type DCTIME

3.4.5 AddDintThis method adds a value of the data type DINT to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

Page 49: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 49Version: 1.7

SyntaxMETHOD AddDintVAR_INPUT  value : DINT;END_VAR

Sample call:fbJson.AddKey('nNumber');fbJson.AddDint(42);

3.4.6 AddFileTimeThis method adds a value of the data type FILETIME to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddFileTimeVAR_INPUT  value : FILETIME;END_VAR

Sample call:fbJson.AddKey('Timestamp');fbJson.AddFileTime(ftTime); // ftTime is of type FILETIME

3.4.7 AddHexBinaryThis method adds a hex binary value to a property. Usually, a corresponding property was createdbeforehand with the method AddKey() [} 49].

SyntaxMETHOD AddHexBinaryVAR_INPUT  pBytes : POINTER TO BYTE;  nBytes : DINT;END_VAR

Sample call:fbJson.AddKey('HexBinary');fbJson.AddHexBinary(ADR(byteHexBin), SIZEOF(byteHexBin));

3.4.8 AddKeyThis method adds a new property key at the current position of the SAX writer. The value of the new propertyis usually set afterwards. This can be done using one of the following methods, for example: AddBase64[} 47], AddBool [} 48], AddDateTime [} 48], AddDcTime [} 48], AddDint [} 48], AddFileTime [} 49],AddHexBinary [} 49], AddLint [} 52], AddLreal [} 52], AddNull [} 52], AddRawArray [} 52],AddRawObject [} 53], AddReal [} 53], AddString [} 53], AddUdint [} 53], AddUlint [} 54].

SyntaxMETHOD AddKeyVAR_IN_OUT CONSTANT  key : STRING;END_VAR

Sample call:fbJson.AddKey('PropertyName');

Page 50: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100050 Version: 1.7

3.4.9 AddKeyBoolThis method creates a new property key and at the same time a value of the data type BOOL.

SyntaxMETHOD AddKeyBoolVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : BOOL;END_VAR

Sample call:fbJson.AddKeyBool('bSwitch', TRUE);

3.4.10 AddKeyDateTimeThis method creates a new property key and at the same time a value of the data type DATE_AND_TIME.

SyntaxMETHOD AddKeyDateTimeVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : DATE_AND_TIME;END_VAR

Sample call:fbJson.AddKeyDateTime('Timestamp', dtTime);

3.4.11 AddKeyDcTimeThis method creates a new property key and at the same time a value of the data type DCTIME.

SyntaxMETHOD AddKeyDcTimeVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : DCTIME;END_VAR

Sample call:fbJson.AddKeyDcTime('Timestamp', dcTime);

3.4.12 AddKeyFileTimeThis method creates a new property key and at the same time a value of the data type FILETIME.

SyntaxMETHOD AddKeyFileTimeVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : FILETIME;END_VAR

Page 51: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 51Version: 1.7

Sample call:fbJson.AddKeyFileTime('Timestamp', ftTime);

3.4.13 AddKeyLrealThis method creates a new property key and at the same time a value of the data type LREAL.

SyntaxMETHOD AddKeyLrealVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : LREAL;END_VAR

Sample call:fbJson.AddKeyLreal('PropertyName', 42.42);

3.4.14 AddKeyNullThis method creates a new property key and initializes its value with zero.

SyntaxMETHOD AddKeyNullVAR_IN_OUT CONSTANT  key : STRING;END_VAR

Sample call:fbJson.AddKeyNull('PropertyName');

3.4.15 AddKeyNumberThis method creates a new property key and at the same time a value of the data type DINT.

SyntaxMETHOD AddKeyNumberVAR_IN_OUT CONSTANT  key : STRING;END_VARVAR_INPUT  value : DINT;END_VAR

Sample call:fbJson.AddKeyNumber('PropertyName', 42);

3.4.16 AddKeyStringThis method creates a new property key and at the same time a value of the data type STRING.

SyntaxMETHOD AddKeyStringVAR_IN_OUT CONSTANT  key : STRING;  value : STRING;END_VAR

Page 52: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100052 Version: 1.7

Sample call:fbJson.AddKeyString('PropertyName', 'Hello World');

3.4.17 AddLintThis method adds a value of the data type LINT to a property. Usually, a corresponding property was createdbeforehand with the method AddKey() [} 49].

SyntaxMETHOD AddLintVAR_INPUT  value : LINT;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddLint(42);

3.4.18 AddLrealThis method adds a value of the data type LREAL to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddLrealVAR_INPUT  value : LREAL;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddLreal(42.42);

3.4.19 AddNullThis method adds the value zero to a property. Usually, a corresponding property was created beforehandwith the method AddKey() [} 49].

SyntaxMETHOD AddNull

Sample call:fbJson.AddKey('PropertyName');fbJson.AddNull();

3.4.20 AddRawArrayThis method adds a valid JSON array to a given property as a value. The array to be added must be in avalid JSON format and may only be added if the SAX writer is at a correspondingly valid position, i.e. forexample, directly after a preceding AddKey() [} 49], StartArray() [} 55] or as the first call after aResetDocument() [} 55].

SyntaxMETHOD AddRawArrayVAR_IN_OUT CONSTANT  rawJson : STRING;END_VAR

Page 53: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 53Version: 1.7

Sample call:fbJson.AddKey('PropertyName');fbJson.AddRawArray('[1, 2, {"x":42, "y":42}, 4');

3.4.21 AddRawObjectThis method adds a valid JSON object to a given property as a value. The object to be added must be in avalid JSON format and may only be added if the SAX writer is at a correspondingly valid position, i.e. forexample, directly after a preceding AddKey() [} 49], StartArray() [} 55] or as the first call after aResetDocument() [} 55].

SyntaxMETHOD AddRawObjectVAR_IN_OUT CONSTANT  rawJson : STRING;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddRawObject('{"x":42, "y":42}');

3.4.22 AddRealThis method adds a value of the data type REAL to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddRealVAR_INPUT  value : REAL;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddReal(42.42);

3.4.23 AddStringThis method adds a value of the data type STRING to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddStringVAR_IN_OUT CONSTANT  value : STRING;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddString('Hello World');

3.4.24 AddUdintThis method adds a value of the data type UDINT to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

Page 54: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100054 Version: 1.7

SyntaxMETHOD AddUdintVAR_INPUT  value : UDINT;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddUdint(42);

3.4.25 AddUlintThis method adds a value of the data type ULINT to a property. Usually, a corresponding property wascreated beforehand with the method AddKey() [} 49].

SyntaxMETHOD AddUlintVAR_INPUT  value : ULINT;END_VAR

Sample call:fbJson.AddKey('PropertyName');fbJson.AddUlint(42);

3.4.26 CopyDocumentThis method copies the content of the current JSON object created with the SAX Writer to a target variableof the data type STRING, which can be of any length. The method returns the length of the string (includingnull termination). If the target buffer is too small, it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyDocument : UDINTVAR_IN_OUT CONSTANT  pDoc : STRING;END_VARVAR_INPUT  nDoc : UDINT;END_VAR

Sample call:fbJson.CopyDocument(sTargetString, SIZEOF(sTargetString));

3.4.27 EndArrayThis method generates the end of a started JSON array ("square closing bracket") and inserts it at thecurrent position of the SAX writer.

SyntaxMETHOD EndArray()

Sample call:fbJson.EndArray();

3.4.28 EndObjectThis method generates the end of a started JSON object ("curly closing bracket") and inserts it at the currentposition of the SAX writer.

Page 55: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 55Version: 1.7

SyntaxMETHOD EndObject

Sample call:fbJson.EndObject();

3.4.29 GetDocumentThis method returns the content of the JSON object that is currently created with the SAX Writer and returnsit as data type STRING(255).

The maximum size of the string returned by the method is 255 characters. With longer strings, the methodwill return a NULL string. In this case the method CopyDocument [} 54]() must be used.

SyntaxMETHOD GetDocument : STRING(255)

Sample call:sTargetString := fbJson.GetDocument();

3.4.30 GetDocumentLengthThis method returns the length of the JSON object that is currently created with the SAX Writer and returns itas data type UDINT.

SyntaxMETHOD GetDocumentLength : UDINT

Sample call:nLength := fbJson.GetDocumentLength();

3.4.31 GetMaxDecimalPlaces

3.4.32 ResetDocumentThis method resets the JSON object currently created with the SAX writer.

SyntaxMETHOD ResetDocument

Sample call:fbJson.ResetDocument();

3.4.33 SetMaxDecimalPlaces

3.4.34 StartArrayThis method generates the start of a new JSON array ("square opening bracket") and inserts it at the currentposition of the SAX writer.

SyntaxMETHOD StartArray()

Page 56: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100056 Version: 1.7

Sample call:fbJson.StartArray();

3.4.35 StartObjectThis method generates the start of a new JSON object ("curly opening bracket") and inserts it at the currentposition of the SAX writer.

SyntaxMETHOD StartObject

Sample call:fbJson.StartObject();

3.5 FB_JsonReadWriteDataType

3.5.1 AddJsonKeyPropertiesFromSymbolWith the aid of this method, metadata can be added via PLC attributes to the JSON representation of a PLCdata structure on an FB_JsonSaxWriter [} 47] object. The method receives as its input parameters theinstance of the FB_JsonSaxWriter function block, the desired name of the JSON property that is to containthe metadata, the data type name of the structure and a string variable sProperties, which contains a list ofthe PLC attributes to be extracted, separated by a cross bar.

SyntaxMETHOD AddJsonValueFromSymbol : BOOLVAR_IN_OUT  fbWriter    : FB_JsonSaxWriter;END_VARVAR_IN_OUT CONSTANT  sKey        : STRING;  sDatatype   : STRING;  sProperties : STRING;END_VAR

The PLC attributes can be specified in the following form on the structure elements:{attribute 'Unit' := 'm/s'}{attribute 'DisplayName' := 'Speed'}Sensor1 : REAL;

A complete sample of how to use this method can be found in section Tc3JsonXmlSampleJsonDataType[} 94].

Sample call:fbJsonSaxWriter.ResetDocument()fbJsonDataType.AddJsonKeyPropertiesFromSymbol(fbJsonSaxWriter, 'MetaData','ST_Values','Unit|DisplayName');

3.5.2 AddJsonKeyValueFromSymbolThis method generates the JSON representation of a PLC data structure on an FB_JsonSaxWriter [} 47]object. The method receives as its input parameters the instance of the FB_JsonSaxWriter function block,the data type name of the structure, and the address and size of the source structure instance. As a result,the FB_JsonSaxWriter instance contains a valid JSON representation of the structure. Unlike the methodAddJsonValueFromSymbol() [} 57], the elements of the source structure are nested here in a JSON sub-object whose name can be specified via the input/output parameter sKey.

Page 57: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 57Version: 1.7

SyntaxMETHOD AddJsonValueFromSymbol : BOOLVAR_IN_OUT  fbWriter  : FB_JsonSaxWriter;END_VARVAR_IN_OUT CONSTANT  sKey      : STRING;  sDatatype : STRING;END_VARVAR_INPUT  nData     : UDINT;  pData     : PVOID;END_VAR

A complete sample of how to use this method can be found in section Tc3JsonXmlSampleJsonDataType[} 94].

Sample call:fbJsonSaxWriter.ResetDocument()fbJsonDataType.AddJsonKeyValueFromSymbol(fbJsonSaxWriter, 'Values','ST_Values',SIZEOF(stValues),ADR(stValues));

3.5.3 AddJsonValueFromSymbolThis method generates the JSON representation of a PLC data structure on an FB_JsonSaxWriter [} 47]object. The method receives as its input parameters the instance of the FB_JsonSaxWriter function block,the data type name of the structure, and the address and size of the source structure instance. As a result,the FB_JsonSaxWriter instance contains a valid JSON representation of the structure.

SyntaxMETHOD AddJsonValueFromSymbol : BOOLVAR_IN_OUT  fbWriter : FB_JsonSaxWriter;END_VARVAR_IN_OUT CONSTANT  sDatatype : STRING;END_VARVAR_INPUT  nData : UDINT;  pData : PVOID;END_VAR

A complete sample of how to use this method can be found in section Tc3JsonXmlSampleJsonDataType[} 94].

Sample call:fbJsonSaxWriter.ResetDocument()fbJsonDataType.AddJsonValueFromSymbol(fbJsonSaxWriter,'ST_Values',SIZEOF(stValues), ADR(stValues));

3.5.4 CopyJsonStringFromSymbolThis method generates the JSON representation of a symbol and copies it into a variable of the data typeSTRING, which can be of any length. The method returns the length of the string (including null termination).If the target buffer is too small, it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyJsonStringFromSymbol : UDINTVAR_INPUT  nData : UDINT;  nDoc  : UDINT;  pData : PVOID;END_VARVAR_IN_OUT CONSTANT

Page 58: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100058 Version: 1.7

  pDoc      : STRING;  sDatatype : STRING;END_VAR

Sample call:nLen :=fbJsonDataType.CopyJsonStringFromSymbol('ST_Test',SIZEOF(stTest),ADR(stTest),sString,SIZEOF(sString));

3.5.5 CopyJsonStringFromSymbolPropertiesThis method generates a corresponding JSON representation of PLC attributes on a symbol. In contrast tothe AddJsonKeyPropertiesFromSymbol [} 56] method, the result is not written to an instance of the functionblock FB_JsonSaxWriter, but to a string variable. The method receives as its input parameters the data typename of the symbol and a string variable that represents a list of the PLC attributes to be extracted,separated by a cross bar.

The method copies this JSON representation into a variable of the data type STRING, which can be of anylength. The method returns the length of the string (including null termination). If the target buffer is too small,it is emptied by a null termination and returned as length 0.

SyntaxMETHOD CopyJsonStringFromSymbolProperties : UDINTVAR_INPUT  nDoc  : UDINT;END_VARVAR_IN_OUT CONSTANT  pDoc        : STRING;  sDatatype   : STRING;  sProperties : STRING;END_VAR

Sample call:nLen := fbJsonDataType.CopyJsonStringFromSymbolProperties('ST_Test','Unit|DisplayName',sString,SIZEOF(sString));

3.5.6 GetDataTypeNameByAddressThis method returns the data type name of a transferred symbol.

SyntaxMETHOD GetDataTypeNameByAddress : STRINGVAR_INPUT    nData : UDINT;    pData : PVOID;END_VAR

Sample call:sBuffer := fbJsonDataType.GetDataTypeNameByAddress(SIZEOF(stValues),ADR(stValues));

3.5.7 GetJsonFromSymbolThis method generates the corresponding JSON representation of a symbol. In contrast to theAddJsonValueFromSymbol() [} 57] method, the result is not written to an instance of the function blockFB_JsonSaxWriter, but to a string variable. The method receives as its input parameters the data type nameof the symbol as well as the address and size of the source symbol, e.g. of a structure instance. The addressand size of the destination buffer that contains the JSON representation of the symbol after the call aretransferred as further input parameters.

Page 59: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 59Version: 1.7

SyntaxMETHOD GetJsonFromSymbol : BOOLVAR_IN_OUT CONSTANT  sDatatype : STRING;END_VARVAR_INPUT  nData : UDINT;  pData : PVOID;  nJson : REFERENCE TO UDINT;  pJson : POINTER TO STRING;END_VAR

Input parameter nJsonThe input parameter nJson contains the size of the target buffer when the method is called, and thesize of the actually written JSON object in the target buffer when the method call is completed.

Sample call:fbJsonDataType.GetJsonFromSymbol('ST_Values',SIZEOF(stValues), ADR(stValues), nBufferLength,ADR(sBuffer));

3.5.8 GetJsonStringFromSymbolThis method generates the corresponding JSON representation of a symbol. In contrast to theAddJsonValueFromSymbol() [} 57] method, the result is not written to an instance of the function blockFB_JsonSaxWriter, but to a string variable. The method receives as its input parameters the data type nameof the symbol as well as the address and size of the source symbol, e.g., of a structure instance.

The maximum size of the string returned by the method is 255 characters. With longer strings, the methodwill return a NULL string. In this case the method CopyJsonStringFromSymbol [} 57]() must be used.

SyntaxMETHOD GetJsonStringFromSymbol : STRING(255)VAR_IN_OUT CONSTANT  sDatatype : STRING;END_VARVAR_INPUT  nData : UDINT;  pData : PVOID;END_VAR

Sample call:sBuffer := fbJsonDataType.GetJsonStringFromSymbol('ST_Values',SIZEOF(stValues), ADR(stValues));

3.5.9 GetJsonStringFromSymbolPropertiesThis method generates a corresponding JSON representation of PLC attributes on a symbol. In contrast tothe AddJsonKeyPropertiesFromSymbol [} 56] method, the result is not written to an instance of the functionblock FB_JsonSaxWriter, but to a string variable. The method receives as its input parameters the data typename of the symbol and a string variable that represents a list of the PLC attributes to be extracted,separated by a cross bar. The result is returned directly as the return value of the method.

The maximum size of the string returned by the method is 255 characters. With longer strings, the methodwill return a NULL string. In this case the method CopyJsonStringFromSymbolProperties [} 58]() must beused.

SyntaxMETHOD GetJsonStringFromSymbolProperties : STRING(255)VAR_IN_OUT CONSTANT  sDatatype : STRING;  sProperties : STRING;END_VAR

Sample call:

Page 60: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100060 Version: 1.7

sBuffer := fbJsonDataType.GetJsonStringFromSymbolProperties('ST_Values', 'Unit|DisplayName');

3.5.10 GetSizeJsonStringFromSymbolThis method reads the size of the JSON representation of a symbol. The value is specified with nulltermination.

SyntaxMETHOD GetSizeJsonStringFromSymbol : UDINTVAR_INPUT  nData  :UDINT;  pData  :PVOID;END_VARVAR_IN_OUT CONSTANT  sDatatype   : STRING;END_VAR

Sample call:nLen := fbJsonDataType.GetSizeJsonStringFromSymbol('BOOL',SIZEOF(bBool),ADR(bBool));

3.5.11 GetSizeJsonStringFromSymbolPropertiesThis method reads the size of the JSON representation of PLC attributes on a symbol. The value is specifiedwith null termination.

SyntaxMETHOD GetSizeJsonStringFromSymbolProperties : UDINTVAR_IN_OUT CONSTANT  sDatatype   : STRING;  sProperties : STRING;END_VAR

Sample call:nLen := fbJsonDataType.GetSizeJsonStringFromSymbolProperties('ST_Test','DisplayName|Unit');

3.5.12 GetSymbolNameByAddressThis method returns the complete (ADS) symbol name of a transferred symbol.

SyntaxMETHOD GetSymbolNameByAddress : STRING(255)VAR_INPUT  nData : UDINT;  pData : PVOID;END_VAR

Sample call:sBuffer := fbJsonDataType.GetSymbolNameByAddress(SIZEOF(stValues), ADR(stValues));

3.5.13 SetSymbolFromJsonThis method extracts a string containing a valid JSON message and attempts to save the contents of theJSON object to an equivalent data structure. The method receives as its input parameters the string with theJSON object, the data type name of the target structure, and the address and size of the target structureinstance.

Page 61: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 61Version: 1.7

SyntaxMETHOD SetSymbolFromJson : BOOLVAR_IN_OUT CONSTANT  sJson : STRING;  sDatatype : STRING;END_VARVAR_INPUT  nData : UDINT;  pData : PVOID;END_VAR

Sample call:fbJsonDataType.SetSymbolFromJson(sJson,'ST_Values',SIZEOF(stValuesReceive), ADR(stValuesReceive));

3.6 FB_XmlDomParser

3.6.1 AppendAttributeThis method adds a new attribute to an existing node. The name and value of the new attribute and theexisting XML node are transferred to the method as input parameters. The method returns a reference to thenewly added attribute.

SyntaxMETHOD AppendAttribute : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;  value : STRING;END_VAR

Sample call:objAttribute := fbXml.AppendAttribute(objMachine, 'Name', 'some value');

3.6.2 AppendAttributeAsBoolThis method adds a new attribute to an existing node. The value of the attribute has the data type Boolean.The name and value of the new attribute and the existing XML node are transferred to the method as inputparameters. The method returns a reference to the newly added attribute.

SyntaxMETHOD AppendAttributeAsBool : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : BOOL;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsBool(objMachine, 'Name', TRUE);

3.6.3 AppendAttributeAsDoubleThis method adds a new attribute to an existing node. The value of the attribute has the data type Double.The name and value of the new attribute and the existing XML node are transferred to the method as inputparameters. The method returns a reference to the newly added attribute.

Page 62: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100062 Version: 1.7

SyntaxMETHOD AppendAttributeAsDouble : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : LREAL;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsDouble(objMachine, 'Name', 42.42);

3.6.4 AppendAttributeAsFloatThis method adds a new attribute to an existing node. The value of the attribute has the data type Float. Thename and value of the new attribute and the existing XML node are transferred to the method as inputparameters. The method returns a reference to the newly added attribute.

SyntaxMETHOD AppendAttributeAsFloat : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : REAL;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsFloat(objMachine, 'Name', 42.42);

3.6.5 AppendAttributeAsIntThis method adds a new attribute to an existing node. The value of the attribute has the data type Integer.The name and value of the new attribute and the existing XML node are transferred to the method as inputparameters. The method returns a reference to the newly added attribute.

SyntaxMETHOD AppendAttributeAsInt : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : DINT;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsInt(objMachine, 'Name', 42);

3.6.6 AppendAttributeAsLintThis method adds a new attribute to an existing node. The value of the attribute has the data type Integer64.The name and value of the new attribute and the existing XML node are transferred to the method as inputparameters. The method returns a reference to the newly added attribute.

Page 63: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 63Version: 1.7

SyntaxMETHOD AppendAttributeAsLint : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : LINT;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsLint(objMachine, 'Name', 42);

3.6.7 AppendAttributeAsUintThis method adds a new attribute to an existing node. The value of the attribute has the data type UnsignedInteger. The name and value of the new attribute and the existing XML node are transferred to the methodas input parameters. The method returns a reference to the newly added attribute.

SyntaxMETHOD AppendAttributeAsUint : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : UDINT;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsUint(objMachine, 'Name', 42);

3.6.8 AppendAttributeAsUlintThis method adds a new attribute to an existing node. The value of the attribute has the data type UnsignedInteger64. The name and value of the new attribute and the existing XML node are transferred to the methodas input parameters. The method returns a reference to the newly added attribute.

SyntaxMETHOD AppendAttributeAsUlint : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : ULINT;END_VAR

Sample call:objAttribute := fbXml.AppendAttributeAsUlint(objMachine, 'Name', 42);

3.6.9 AppendAttributeCopyThis method adds a new attribute to an existing node. The name and value of the new attribute are copiedfrom an existing attribute. The existing attribute is transferred to the method as input parameter.

Page 64: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100064 Version: 1.7

SyntaxMETHOD AppendAttributeCopy : SXmlAttributeINPUT_VAR  n : SXmlNode;  copy : SXmlAttribute;END_VAR

Sample call:xmlNewAttribute := fbXml.AppendAttributeCopy(xmlNode, xmlExistingAttribute);

3.6.10 AppendChildThis method inserts a new node below an existing node. The value of the new node has the data typeSTRING. The name and value of the new node and a reference to the existing node are transferred to themethod as input parameters. The method returns a reference to the newly added node. The input parametercdata indicates whether the value of the node is to be encapsulated in a CDATA function block, so thatcertain special characters such as "<" and ">" are allowed as values.

SyntaxMETHOD AppendChild : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;  value : STRING;END_VARVAR_INPUT  cdata : BOOL;END_VAR

Sample call:xmlNewNode := fbXml.AppendChild(xmlExisting, 'Controller', 'CX5120', FALSE);

3.6.11 AppendChildAsBoolThis method inserts a new node below an existing node. The value of the new node has the data typeBoolean. The name and value of the new node and a reference to the existing node are transferred to themethod as input parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendChildAsBool : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : BOOL;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsBool(xmlExisting, 'SomeName', TRUE);

3.6.12 AppendChildAsDoubleThis method inserts a new node below an existing node. The value of the new node has the data typeDouble. The name and value of the new node and a reference to the existing node are transferred to themethod as input parameters. The method returns a reference to the newly added node.

Page 65: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 65Version: 1.7

SyntaxMETHOD AppendChildAsDouble : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : LREAL;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsDouble(xmlExisting, 'SomeName', 42.42);

3.6.13 AppendChildAsFloatThis method inserts a new node below an existing node. The value of the new node has the data type Float.The name and value of the new node and a reference to the existing node are transferred to the method asinput parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendChildAsFloat : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : REAL;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsFloat(xmlExisting, 'SomeName', 42.42);

3.6.14 AppendChildAsIntThis method inserts a new node below an existing node. The value of the new node has the data typeInteger. The name and value of the new node and a reference to the existing node are transferred to themethod as input parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendChildAsInt : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : DINT;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsInt(xmlExisting, 'SomeName', 42);

3.6.15 AppendChildAsLintThis method inserts a new node below an existing node. The value of the new node has the data typeInteger64. The name and value of the new node and a reference to the existing node are transferred to themethod as input parameters. The method returns a reference to the newly added node.

Page 66: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100066 Version: 1.7

SyntaxMETHOD AppendChildAsLint : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : LINT;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsLint(xmlExisting, 'SomeName', 42);

3.6.16 AppendChildAsUintThis method inserts a new node below an existing node. The value of the new node has the data typeUnsigned Integer. The name and value of the new node and a reference to the existing node are transferredto the method as input parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendChildAsUint : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : UDINT;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsUint(xmlExisting, 'SomeName', 42);

3.6.17 AppendChildAsUlintThis method inserts a new node below an existing node. The value of the new node has the data typeUnsigned Integer64. The name and value of the new node and a reference to the existing node aretransferred to the method as input parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendChildAsUlint : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VARVAR_INPUT  value : ULINT;END_VAR

Sample call:xmlNewNode := fbXml.AppendChildAsUlint(xmlExisting, 'SomeName', 42);

3.6.18 AppendCopyThis method inserts a new node below an existing node. The name and value of the new node are copiedfrom an existing node. The references to the existing nodes are transferred to the method as inputparameters. The method returns a reference to the newly added node.

Page 67: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 67Version: 1.7

SyntaxMETHOD AppendCopy : SXmlNodeVAR_INPUT  n : SXmlNode;  copy : SXmlNode;END_VAR

Sample call:xmlNewNode := fbXml.AppendCopy(xmlParentNode, xmlExistingNode);

3.6.19 AppendNodeThis method adds a new node to an existing node. The existing node and the name of the new node aretransferred to the method as input parameters. The method returns a reference to the newly added node.

SyntaxMETHOD AppendNode : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:objMachines := fbXml.AppendNode(objRoot, 'Machines');

3.6.20 AttributesThis method can be used to read the attribute of a given XML node. The XML node and the name of theattribute are transferred to the method as input parameters. After the method has been called, furthermethods have to be called, for example to read the value of the attribute, e.g. AttributeAsInt().

SyntaxMETHOD Attribute : SXmlAttributeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlMachine1Attribute := fbXml.Attribute(xmlMachine1, 'Type');

3.6.21 AttributeAsBoolThis method returns the value of an attribute as data type Boolean. The attribute is transferred to the methodas input parameter.

SyntaxMETHOD AttributeAsBool : BOOLVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:bValue := fbXml.AttributeAsBool(xmlAttr);

Page 68: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100068 Version: 1.7

3.6.22 AttributeAsDoubleThis method returns the value of an attribute as data type Double. The attribute is transferred to the methodas input parameter.

SyntaxMETHOD AttributeAsDouble : LREALVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:lrValue := fbXml.AttributeAsDouble(xmlAttr);

3.6.23 AttributeAsFloatThis method returns the value of an attribute as data type Float. The attribute is transferred to the method asinput parameter.

SyntaxMETHOD AttributeAsFloat : REALVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:rValue := fbXml.AttributeAsFloat(xmlAttr);

3.6.24 AttributeAsIntThis method returns the value of an attribute as a data type Integer. The attribute is transferred to themethod as input parameter.

SyntaxMETHOD AttributeAsInt : DINTVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:nValue := fbXml.AttributeAsInt(xmlAttr);

3.6.25 AttributeAsLintThis method returns the value of an attribute as a data type Integer64. The attribute is transferred to themethod as input parameter.

SyntaxMETHOD AttributeAsLint : LINTVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:nValue := fbXml.AttributeAsLint(xmlAttr);

Page 69: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 69Version: 1.7

3.6.26 AttributeAsUintThis method returns the value of an attribute as data type Unsigned Integer. The attribute is transferred tothe method as input parameter.

SyntaxMETHOD AttributeAsUint : UDINTVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:nValue := fbXml.AttributeAsUint(xmlAttr);

3.6.27 AttributeAsUlintThis method returns the value of an attribute as data type Unsigned Integer64. The attribute is transferred tothe method as input parameter.

SyntaxMETHOD AttributeAsUlint : ULINTVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:nValue := fbXml.AttributeAsUlint(xmlAttr);

3.6.28 AttributeBeginThis method returns an iterator over all attributes of an XML node. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD AttributeBegin : SXmlIteratorVAR_INPUT  n : SXmlNode;END_VAR

Sample call:xmlIterator := fbXml.AttributeBegin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlAttr := fbXml.AttributeFromIterator(xmlIterator);  nAttrValue := fbXml.AttributeAsInt(xmlAttr);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.29 AttributeFromIteratorThis method converts the current position of an iterator to an XML attribute object. The iterator is transferredto the method as input parameter.

SyntaxMETHOD AttributeFromIterator : SXmlAttributeVAR_INPUT  it : SXmlIterator;END_VAR

Sample call:

Page 70: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100070 Version: 1.7

xmlIterator := fbXml.AttributeBegin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlAttr := fbXml.AttributeFromIterator(xmlIterator);  nAttrValue := fbXml.AttributeAsInt(xmlAttr);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.30 AttributeNameThis method returns the name of a given attribute. The attribute is transferred to the method as inputparameter.

SyntaxMETHOD AttributeName : STRINGVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:sName := fbXml.AttributeName(xmlAttr);

3.6.31 AttributesThis method is used to navigate through the DOM and returns an iterator for all attributes found at an XMLnode. The iterator can then be used for further navigation through the elements that were found. The nodeand a reference to the iterator are transferred to the method as input parameters.

SyntaxMETHOD Attributes : SXmlAttributeVAR_INPUT  n : SXmlNode;  it : REFERENCE TO SXmlIterator;END_VAR

Sample call:xmlRet := fbXml.Attributes(xmlNode, xmlIterator);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineAttrRef := fbXml.Attribute(xmlIterator);  xmlMachineAttrText := fbXml.AttributeText(xmlMachineAttrRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.32 AttributeTextThis method returns the text of a given attribute. The attribute is transferred to the method as inputparameter.

SyntaxMETHOD AttributeText : STRING(255)VAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:sText := fbXml.AttributeText(xmlAttr);

3.6.33 BeginThis method returns an iterator over all child elements of an XML node, always starting from the first childelement. The XML node is transferred to the method as input parameter.

Page 71: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 71Version: 1.7

SyntaxMETHOD Begin : SXmlIteratorVAR_INPUT  n : SXmlNode;END_VAR

Sample call:xmlIterator := fbXml.Begin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlNodeRef := fbXml.Node(xmlIterator);  xmlNodeValue := fbXml.NodeText(xmlNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.34 BeginByNameThis method returns an iterator over all child elements of an XML node, starting at a particular element. TheXML node is transferred to the method as input parameter.

SyntaxMETHOD BeginByName : SXmlIteratorVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlNode := fbXml.ChildByName(xmlDoc, 'Machines');xmlIterator := fbXml.BeginByName(xmlNode, 'NameX');WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlNodeRef := fbXml.Node(xmlIterator);  xmlNodeValue := fbXml.NodeText(xmlNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.35 ChildThis method is used to navigate through the DOM. It returns a reference to the (first) child element of thecurrent node. The start node is transferred to the method as input parameter.

SyntaxMETHOD ChildByName : SXmlNodeVAR_INPUT  n : SXmlNode;END_VAR

Sample call:xmlChild := fbXml.Child(xmlNode);

3.6.36 ChildByAttributeThis method is used to navigate through the DOM. It returns a reference to a child element in the XMLdocument. The start node and the name and value of the attribute are transferred to the method as inputparameters.

SyntaxMETHOD ChildByAttribute : SXmlNodeVAR_INPUT  n : SXmlNode;END_VAR

Page 72: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100072 Version: 1.7

VAR_IN_OUT CONSTANT  attr : STRING;  value : STRING;END_VAR

Sample call:xmlMachine1 := fbXml.ChildByAttribute(xmlMachines, 'Type', '1');

3.6.37 ChildByAttributeAndNameThis method is used to navigate through the DOM. It returns a reference to a child element in the XMLdocument. The start node, the name and value of the attribute, and the name of the child element aretransferred to the method as input parameters.

SyntaxMETHOD ChildByAttributeAndName : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  attr : STRING;  value : STRING;  child : STRING;END_VAR

Sample call:xmlMachine2 := fbXml.ChildByAttributeAndName(xmlMachines, 'Type', '2', 'Machine');

3.6.38 ChildByNameThis method is used to navigate through the DOM. It returns a reference to a child element in the XMLdocument. The start node and the name of the element to be returned are transferred to the method as inputparameters.

SyntaxMETHOD ChildByName : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlMachines := fbXml.ChildByName(xmlDoc, 'Machines');

3.6.39 ChildrenThis method is used to navigate through the DOM. It returns an iterator for several child elements found inthe XML document. The iterator can then be used for further navigation through the elements that werefound. The start node and a reference to the iterator are transferred to the method as input parameters.

SyntaxMETHOD Children : SXmlNodeVAR_INPUT  n : SXmlNode;  it : REFERENCE TO SXmlIterator;END_VAR

Sample call:

Page 73: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 73Version: 1.7

xmlRet := fbXml.Children(xmlNode, xmlIterator);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineNodeRef := fbXml.Node(xmlIterator);  xmlMachineNodeText := fbXml.NodeText(xmlMachineNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.40 ChildrenByNameThis method is used to navigate through the DOM. It returns an iterator for several child elements found inthe XML document. The iterator can then be used for further navigation through the elements that werefound. The start node, the name of the child elements to be found and a reference to the iterator aretransferred to the method as input parameters.

SyntaxMETHOD ChildrenByName : SXmlNodeVAR_INPUT  n : SXmlNode;  it : REFERENCE TO SXmlIterator;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlMachineNode := fbXml.ChildrenByName(xmlMachines, xmlIterator, 'Machine');WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineNodeRef := fbXml.Node(xmlIterator);  xmlMachineNodeText := fbXml.NodeText(xmlMachineNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.41 CompareThis method checks two iterators for equality.

SyntaxMETHOD Compare : BOOLVAR_INPUT  it1 : SXmlIterator;  it2 : SXmlIterator;END_VAR

Sample call:bResult := fbXml.Compare(xmlIt1, xmlIt2);

3.6.42 CopyAttributeTextThis method reads the value of an XML attribute and writes it to a variable of data type String. The XMLattribute, the target variable and the length to be written are transferred to the method as input parameters.The method returns the actual size.

SyntaxMETHOD CopyAttributeText : UDINTVAR_INPUT  a : SXmlAttribute;END_VARVAR_IN_OUT CONSTANT  sXml : STRING;END_VARVAR_INPUT  nXml : UDINT;END_VAR

Page 74: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100074 Version: 1.7

Sample call:nLength := fbXml.CopyAttributeText(xmlAttr, sTarget, SIZEOF(sTarget));

3.6.43 CopyDocumentThis method copies the contents of the DOM memory into a variable of the data type String. The length to bewritten and the variable into which the resulting string is to be written are transferred to the method as inputparameters. The method returns the actually written length. Note that the size of the string variable is at leastequal to the size of the XML document in the DOM.

SyntaxMETHOD CopyDocument : UDINTVAR_IN_OUT CONSTANT  sXml : STRING;END_VARVAR_INPUT  nXml : UDINT;END_VAR

Sample call:nLength := fbXml.CopyDocument(sTarget, SIZEOF(sTarget));

3.6.44 CopyNodeTextThis method reads the value of an XML node and writes it to a variable of data type String. The XML node,the target variable and the length to be written are transferred to the method as input parameters. Themethod returns the actual size.

SyntaxMETHOD CopyNodeText : UDINTVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  sXml : STRING;END_VARVAR_INPUT  nXml : UDINT;END_VAR

Sample call:nLength := fbXml.CopyNodeText(xmlNode, sTarget, SIZEOF(sTarget));

3.6.45 CopyNodeXmlThis method reads the XML structure of an XML node and writes it to a variable of data type String. The XMLnode, the target variable and the length to be written are transferred to the method as input parameters. Themethod returns the actual size.

SyntaxMETHOD CopyNodeXml : UDINTVAR_INPUT  a : SXmlNode;END_VARVAR_IN_OUT CONSTANT  sXml : STRING;END_VARVAR_INPUT  nXml : UDINT;END_VAR

Sample call:

Page 75: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 75Version: 1.7

nLength := fbXml.CopyNodeXml(xmlNode, sTarget, SIZEOF(sTarget));

3.6.46 FirstNodeByPathThis method navigates through an XML document using a path that was transferred to the method. The pathand the start node are transferred to the method as input parameters. The path is specified with "/" asseparator. The method returns a reference to the XML node that was found.

SyntaxMETHOD FirstNodeByPath : SXmlNodeVAR_INPUT  n : SXmlNode;  path : STRING;END_VAR

Sample call:xmlFoundNode := fbXml.FirstNodeByPath(xmlStartNode, 'Level1/Level2/Level3');

3.6.47 GetAttributeTextLengthThis method returns the length of the value of an XML attribute. The XML attribute is transferred to themethod as input parameter.

SyntaxMETHOD GetAttributeTextLength : UDINTVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:nLength := fbXml.GetAttributeTextLength(xmlAttr);

3.6.48 GetDocumentLengthThis method returns the length of an XML document in bytes.

SyntaxMETHOD GetDocumentLength : UDINT

Sample call:nLength := fbXml.GetDocumentLength();

3.6.49 GetDocumentNodeThis method returns the root node of an XML document. This is not the same as the first XML node in thedocument (the method GetRootNode() should be used for this). The method can also be used to create anempty XML document in the DOM.

SyntaxMETHOD GetDocumentNode : SXmlNode

Sample call:objRoot := fbXml.GetDocumentNode();

Page 76: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100076 Version: 1.7

3.6.50 GetNodeTextLengthThis method returns the length of the value of an XML node. The XML node is transferred to the method asinput parameter.

SyntaxMETHOD GetNodeTextLength : UDINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nLength := fbXml.GetNodeTextLength(xmlNode);

3.6.51 GetNodeXmlLengthThis method returns the length of the XML structure of an XML node. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD GetNodeXmlLength : UDINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nLength := fbXml.GetNodeXmlLength(xmlNode);

3.6.52 GetRootNodeThis method returns a reference to the first XML node in the XML document.

SyntaxMETHOD GetRootNode : SXmlNode

Sample call:xmlRootNode := fbXml.GetRootNode();

3.6.53 InsertAttributeCopyThis method adds an attribute to an XML node. The name and value of an existing attribute are copied. Theattribute can be placed at a specific position. The XML node, the position and a reference to the existingattribute object are transferred to the method as input parameters. The method returns a reference to thenewly added attribute.

SyntaxMETHOD InsertAttributeCopy : SXmlAttributeVAR_INPUT  n : SXmlNode;  before : SXmlAttribute;  copy : SXmlAttribute;END_VAR

Sample call:xmlNewAttr := fbXml.InsertAttributeCopy(xmlNode, xmlBeforeAttr, xmlCopyAttr);

Page 77: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 77Version: 1.7

3.6.54 InsertAttributeThis method adds an attribute to an XML node. The attribute can be placed at a specific position. The XMLnode and the position and name of the new attribute are transferred to the method as input parameters. Themethod returns a reference to the newly added attribute. A value for the attribute can then be entered usingthe SetAttribute() method, for example.

SyntaxMETHOD InsertAttribute : SXmlAttributeVAR_INPUT  n : SXmlNode;  before : SXmlAttribute;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlNewAttr := fbXml.InsertAttribute(xmlNode, xmlBeforeAttr, 'SomeName');

3.6.55 InsertChildThis method adds a node to an existing XML node. The new node can be placed at a specific location. Theexisting XML node and the position and name of the new node are transferred to the method as inputparameters. The method returns a reference to the newly added node. A value for the node can then beentered using the SetChild() method, for example.

SyntaxMETHOD InsertChild : SXmlNodeVAR_INPUT  n : SXmlNode;  before : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlNewNode := fbXml.InsertChild(xmlNode, xmlBeforeNode, 'SomeName');

3.6.56 InsertCopyThis method adds a new node to an existing XML node and copies an existing node. The new node can beplaced anywhere in the existing node. The XML node, the position and a reference to the existing nodeobject are transferred to the method as input parameters. The method returns a reference to the newlyadded node.

SyntaxMETHOD InsertCopy : SXmlNodeVAR_INPUT  n : SXmlNode;  before : SXmlNode;  copy : SXmlNode;END_VAR

Sample call:xmlNewNode := fbXml.InsertCopy(xmlNode, xmlBeforeNode, xmlCopyNode);

3.6.57 IsEndThis method checks whether a given XML iterator is at the end of the iteration that is to be performed.

Page 78: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100078 Version: 1.7

SyntaxMETHOD IsEnd : BOOLVAR_INPUT  it : SXmlIterator;END_VAR

Sample call:xmlIterator := fbXml.Begin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlNodeRef := fbXml.Node(xmlIterator);  xmlNodeValue := fbXml.NodeText(xmlNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.58 LoadDocumentFromFileThis method loads an XML document from a file. The absolute path to the file is transferred to the method asinput parameter. A rising edge on the input parameter bExec triggers the loading procedure. Following thesuccessful loading of a file, the return value of the method jumps to TRUE for one cycle and is thenautomatically reset by the driver.

SyntaxMETHOD LoadDocumentFromFile : BOOLVAR_IN_OUT CONSTANT  sFile : STRING;END_VARVAR_INPUT  bExec : REFERENCE TO BOOL;END_VAR

Sample call:bLoaded := fbXml.LoadDocumentFromFile('C:\Test.xml', bLoad);

3.6.59 NewDocumentThis method creates an empty XML document in the DOM memory.

SyntaxMETHOD NewDocument : BOOL

Sample call:fbXml.NewDocument();

3.6.60 NextThis method sets an XML iterator for the next object that is to be processed.

SyntaxMETHOD Next : SXmlIteratorVAR_INPUT  it : SXmlIterator;END_VAR

Sample call:xmlIterator := fbXml.Begin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlNodeRef := fbXml.Node(xmlIterator);  xmlNodeValue := fbXml.NodeText(xmlNodeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

Page 79: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 79Version: 1.7

3.6.61 NextAttributeThis method returns the next attribute for a given XML attribute.

SyntaxMETHOD NextAttribute : SXmlAttributeVAR_INPUT  a : SXmlAttribute;END_VAR

Sample call:xmlNextAttr := fbXml.NextAttribute(xmlAttr);

3.6.62 NextByNameThis method sets an XML iterator for the next object that is to be processed, which is identified by its name.

SyntaxMETHOD NextByName : SXmlIteratorVAR_INPUT  it : SXmlIterator;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:xmlIterator := fbXml.Begin(xmlNode);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlNodeRef := fbXml.Node(xmlIterator);  xmlNodeValue := fbXml.NodeText(xmlNodeRef);  xmlIterator := fbXml.NextByName(xmlIterator, 'SomeName');END_WHILE

3.6.63 NextSiblingThis method returns the next direct node for a given XML node at the same XML level.

SyntaxMETHOD NextSibling : SXmlNodeVAR_INPUT  n : SXmlNode;END_VAR

Sample call:xmlSibling := fbXml.NextSibling(xmlNode);

3.6.64 NextSiblingByNameThis method returns the next direct node for a given XML node with a particular name at the same XMLlevel.

SyntaxMETHOD NextSiblingByName : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Page 80: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100080 Version: 1.7

Sample call:xmlSibling := fbXml.NextSibling(xmlNode, 'SomeName');

3.6.65 NodeThis method is used in conjunction with an iterator to navigate through the DOM. The iterator is transferredto the method as input parameter. The method then returns the current XML node as return value.

SyntaxMETHOD Node : SXmlNodeVAR_INPUT  it : SXmlIterator;END_VAR

Sample call:xmlMachineNode := fbXml.ChildrenByName(xmlMachines, xmlIterator, 'Machine');WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineNode := fbXml.Node(xmlIterator);  xmlMachineNodeValue := fbXml.NodeText(xmlMachineNode);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

3.6.66 NodeAsBoolThis method returns the text of an XML node as data type Boolean. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD NodeAsBool : BOOLVAR_INPUT  n : SXmlNode;END_VAR

Sample call:bXmlNode:= fbXml.NodeAsBool(xmlMachine1);

3.6.67 NodeAsDoubleThis method returns the text of an XML node as data type Double. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD NodeAsDouble : LREALVAR_INPUT  n : SXmlNode;END_VAR

Sample call:lrXmlNode:= fbXml.NodeAsDouble(xmlMachine1);

3.6.68 NodeAsFloatThis method returns the text of an XML node as data type Float. The XML node is transferred to the methodas input parameter.

Page 81: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 81Version: 1.7

SyntaxMETHOD NodeAsFloat : REALVAR_INPUT  n : SXmlNode;END_VAR

Sample call:rXmlNode:= fbXml.NodeAsFloat(xmlMachine1);

3.6.69 NodeAsIntThis method returns the text of an XML node as a data type Integer. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD NodeAsInt : DINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nXmlNode:= fbXml.NodeAsInt(xmlMachine1);

3.6.70 NodeAsLintThis method returns the text of an XML node as a data type Integer64. The XML node is transferred to themethod as input parameter.

SyntaxMETHOD NodeAsLint : LINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nXmlNode:= fbXml.NodeAsLint(xmlMachine1);

3.6.71 NodeAsUintThis method returns the text of an XML node as data type Unsigned Integer. The XML node is transferred tothe method as input parameter.

SyntaxMETHOD NodeAsUint : UDINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nXmlNode:= fbXml.NodeAsUint(xmlMachine1);

3.6.72 NodeAsUlintThis method returns the text of an XML node as data type Unsigned Integer64. The XML node is transferredto the method as input parameter.

Page 82: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100082 Version: 1.7

SyntaxMETHOD NodeAsUlint : ULINTVAR_INPUT  n : SXmlNode;END_VAR

Sample call:nXmlNode:= fbXml.NodeAsUlint(xmlMachine1);

3.6.73 NodeNameThis method returns the name of an XML node. A reference to the XML node is transferred to the method asinput parameter.

SyntaxMETHOD NodeName : STRINGVAR_INPUT  n : SXmlNode;END_VAR

Sample call:sNodeName := fbXml.NodeName(xmlMachine1);

3.6.74 NodeTextThis method returns the text of an XML node. The XML node is transferred to the method as inputparameter.

SyntaxMETHOD NodeText : STRING(255)VAR_INPUT  n : SXmlNode;END_VAR

Sample call:sMachine1Name := fbXml.NodeText(xmlMachine1);

3.6.75 ParseDocumentThis method loads an XML document into the DOM memory for further processing. The XML documentexists as a string and is transferred to the method as input parameter. A reference to the XML document inthe DOM is returned to the caller.

SyntaxMETHOD ParseDocument : SXmlNodeVAR_IN_OUT CONSTANT  sXml : STRING;END_VAR

Sample call:xmlDoc := fbXml.ParseDocument(sXmlToParse);

3.6.76 RemoveChildThis method removes an XML child node from a given XML node. The two XML nodes are transferred to themethod as input parameters. The method returns TRUE if the operation was successful and the XML nodewas removed.

Page 83: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 83Version: 1.7

SyntaxMETHOD RemoveChild : BOOLVAR_INPUT  n : SXmlNode;  child : SXmlNode;END_VAR

Sample call:bRemoved := fbXml.RemoveChild(xmlParent, xmlChild);

3.6.77 RemoveChildByNameThis method removes an XML child node from a given XML node. The node to be removed is addressed byits name. If there is more than one child node, the last child node is removed. The method returns TRUE ifthe operation was successful and the XML node was removed.

SyntaxMETHOD RemoveChildByName : BOOLVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  name : STRING;END_VAR

Sample call:bRemoved := fbXml.RemoveChildByName(xmlParent, 'SomeName');

3.6.78 SaveDocumentToFileThis method saves the current XML document in a file. The absolute path to the file is transferred to themethod as input parameter. A rising edge at the input parameter bExec triggers the saving procedure.Following the successful saving of a file, the return value of the method jumps to TRUE for one cycle and isthen automatically reset by the driver.

SyntaxMETHOD SaveDocumentToFile : BOOLVAR_IN_OUT CONSTANT  sFile : STRING;END_VARVAR_INPUT  bExec : REFERENCE TO BOOL;END_VAR

Sample call:bSaved = fbXml.SaveDocumentToFile('C:\Test.xml', bSave);

3.6.79 SetAttributeThis method sets the value of an attribute. The value has the data type String.

SyntaxMETHOD SetAttribute : SXmlAttributeVAR_INPUT  a : SXmlAttribute;END_VARVAR_IN_OUT CONSTANT  value : STRING;END_VAR

Sample call:

Page 84: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100084 Version: 1.7

xmlAttr := fbXml.SetAttribute(xmlExistingAttr, 'Test');

3.6.80 SetAttributeAsBoolThis method sets the value of an attribute. The value has the data type Boolean.

SyntaxMETHOD SetAttributeAsBool : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : BOOL;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsBool(xmlExistingAttr, TRUE);

3.6.81 SetAttributeAsDoubleThis method sets the value of an attribute. The value here has the data type Double.

SyntaxMETHOD SetAttributeAsDouble : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : LREAL;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsDouble(xmlExistingAttr, 42.42);

3.6.82 SetAttributeAsFloatThis method sets the value of an attribute. The value has the data type Float.

SyntaxMETHOD SetAttributeAsFloat : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : REAL;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsFloat(xmlExistingAttr, 42.42);

3.6.83 SetAttributeAsIntThis method sets the value of an attribute. The value has the data type Integer.

SyntaxMETHOD SetAttributeAsInt : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : DINT;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsInt(xmlExistingAttr, 42);

Page 85: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 85Version: 1.7

3.6.84 SetAttributeAsLintThis method sets the value of an attribute. The value has the data type Integer64.

SyntaxMETHOD SetAttributeAsLint : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : LINT;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsLint(xmlExistingAttr, 42);

3.6.85 SetAttributeAsUintThis method sets the value of an attribute. The value has the data type Unsigned Integer.

SyntaxMETHOD SetAttributeAsUint : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : UDINT;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsUint(xmlExistingAttr, 42);

3.6.86 SetAttributeAsUlintThis method sets the value of an attribute. The value has the data type Unsigned Integer64.

SyntaxMETHOD SetAttributeAsUlint : SXmlAttributeVAR_INPUT  a : SXmlAttribute;  value : ULINT;END_VAR

Sample call:xmlAttr := fbXml.SetAttributeAsUlint(xmlExistingAttr, 42);

3.6.87 SetChildThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type String. The input parameter cdata indicates whether the value of the node is to be encapsulated ina CDATA function block, so that certain special characters such as "<" and ">" are allowed as values.

SyntaxMETHOD SetChild : SXmlNodeVAR_INPUT  n : SXmlNode;END_VARVAR_IN_OUT CONSTANT  value : STRING;END_VARVAR_INPUT  cdata : BOOL;END_VAR

Sample call:

Page 86: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100086 Version: 1.7

xmlNode := fbXml.SetChild(xmlExistingNode, 'SomeText', FALSE);

3.6.88 SetChildAsBoolThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Boolean.

SyntaxMETHOD SetChildAsBool : SXmlNodeVAR_INPUT  n : SXmlNode;  value : BOOL;END_VAR

Sample call:xmlNode := fbXml.SetChild(xmlExistingNode, TRUE);

3.6.89 SetChildAsDoubleThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Double.

SyntaxMETHOD SetChildAsDouble : SXmlNodeVAR_INPUT  n : SXmlNode;  value : LREAL;END_VAR

Sample call:xmlNode := fbXml.SetChildAsDouble(xmlExistingNode, 42.42);

3.6.90 SetChildAsFloatThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Float.

SyntaxMETHOD SetChildAsFloat : SXmlNodeVAR_INPUT  n : SXmlNode;  value : REAL;END_VAR

Sample call:xmlNode := fbXml.SetChildAsFloat(xmlExistingNode, 42.42);

3.6.91 SetChildAsIntThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Integer.

SyntaxMETHOD SetChildAsInt : SXmlNodeVAR_INPUT  n : SXmlNode;  value : DINT;END_VAR

Page 87: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE1000 87Version: 1.7

Sample call:xmlNode := fbXml.SetChildAsInt(xmlExistingNode, 42);

3.6.92 SetChildAsLintThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Integer64.

SyntaxMETHOD SetChildAsLint : SXmlNodeVAR_INPUT  n : SXmlNode;  value : LINT;END_VAR

Sample call:xmlNode := fbXml.SetChildAsLint(xmlExistingNode, 42);

3.6.93 SetChildAsUintThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Unsigned Integer.

SyntaxMETHOD SetChildAsUint : SXmlNodeVAR_INPUT  n : SXmlNode;  value : UDINT;END_VAR

Sample call:xmlNode := fbXml.SetChildAsUint(xmlExistingNode, 42);

3.6.94 SetChildAsUlintThis method sets the value of an XML node. The value is transferred to the method as input parameter ofdata type Unsigned Integer64.

SyntaxMETHOD SetChildAsUlint : SXmlNodeVAR_INPUT  n : SXmlNode;  value : ULINT;END_VAR

Sample call:xmlNode := fbXml.SetChildAsUlint(xmlExistingNode, 42);

3.7 FB_JwtEncodeThe function block enables the creation and signing of a JSON Web Token (JWT).

Syntax

Definition:FUNCTION_BLOCK FB_JwtEncodeVAR_INPUT  bExecute       : BOOL;

Page 88: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Function blocks

TE100088 Version: 1.7

  sHeaderAlg     : STRING(46);  sPayload       : STRING(1023);  sKeyFilePath   : STRING(511);  tTimeout       : TIME;  pKey           : PVOID;  nKeySize       : UDINT;  nJwtSize       : UDINT;END_VARVAR_IN_OUT CONSTANT  sJwt           : STRING;  END_VARVAR_OUTPUT  bBusy          : BOOL;  bError         : BOOL;  hrErrorCode    : HRESULT;  initStatus     : HRESULT;END_VAR

Inputs

Name Type DescriptionbExecute BOOL A rising edge activates processing of the function block.sHeaderAlg STRING(46) The algorithm to be used for the JWT header, e.g.

RS256.sPayload STRING(1023) The JWT payload to be used.sKeyFilePath STRING(511) Path to the private key to be used for the signature of

the JWT.tTimeout TIME ADS timeout, which is used internally for file access to

the private key.pKey PVOID Buffer for the private key to be read.nKeySize UDINT Maximum size of the buffer.sJwt STRING Contains the fully coded and signed JWT after the

function block has been processed.nJwtSize UDINT Size of the generated JWT including zero termination.

Outputs

Name Type DescriptionbBusy BOOL Is TRUE as long as processing of the function block is in

progress.bError BOOL Becomes TRUE as soon as an error situation occurs.hrErrorCode HRESULT Returns an error code if the bError output is set. An

explanation of the possible error codes can be found in theAppendix.

Requirements

TwinCAT version Hardware Libraries to be integratedTwinCAT 3.1, Build 4024.4 x86, x64, ARM Tc3_JsonXml 3.3.6.0

Page 89: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Interfaces

TE1000 89Version: 1.7

4 Interfaces

4.1 ITcJsonSaxHandler

4.1.1 OnBoolThis callback method is triggered if a value of the data type BOOL was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnBool : HRESULTVAR_INPUT    value : BOOL;END_VAR

4.1.2 OnDintThis callback method is triggered if a value of the data type DINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnDint : HRESULTVAR_INPUT    value : DINT;END_VAR

4.1.3 OnEndArrayThis callback method is triggered if a square closing bracket, which corresponds to the JSON synonym foran ending array, was found at the position of the SAX reader. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnEndArray : HRESULT

4.1.4 OnEndObjectThis callback method is triggered if a curly closing bracket, which corresponds to the JSON synonym for anending object, was found at the position of the SAX reader. The SAX parsing procedure is aborted by settingthe return value HRESULT to S_FALSE.

SyntaxMETHOD OnEndObject : HRESULT

4.1.5 OnKeyThis callback method is triggered if a property was found at the position of the SAX reader. The propertyname lies on the input/output parameter key and its length on the input parameter len. The SAX parsingprocedure is aborted by setting the return value HRESULT to S_FALSE.

Page 90: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Interfaces

TE100090 Version: 1.7

SyntaxMETHOD OnKey : HRESULTVAR_IN_OUT CONSTANT    key : STRING;END_VARVAR_INPUT    len : UDINT;END_VAR

4.1.6 OnLintThis callback method is triggered if a value of the data type LINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnLint : HRESULTVAR_INPUT    value : LINT;END_VAR

4.1.7 OnLrealThis callback method is triggered if a value of the data type LREAL was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnLreal : HRESULTVAR_INPUT    value : LREAL;END_VAR

4.1.8 OnNullThis callback method is triggered if a NULL value was found at the position of the SAX reader. The SAXparsing procedure is aborted by setting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnNull : HRESULT

4.1.9 OnStartArrayThis callback method is triggered if a square opening bracket, which corresponds to the JSON synonym for astarting array, was found at the position of the SAX reader. The SAX parsing procedure is aborted by settingthe return value HRESULT to S_FALSE.

SyntaxMETHOD OnStartArray : HRESULT

4.1.10 OnStartObjectThis callback method is triggered if a curly opening bracket, which corresponds to the JSON synonym for astarting object, was found at the position of the SAX reader. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

Page 91: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Interfaces

TE1000 91Version: 1.7

SyntaxMETHOD OnStartObject : HRESULT

4.1.11 OnStringThis callback method is triggered if a value of the data type STRING was found at the position of the SAXreader. The In/Out parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnString : HRESULTVAR_IN_OUT CONSTANT    value : STRING;END_VARVAR_INPUT    len : UDINT;END_VAR

4.1.12 OnUdintThis callback method is triggered if a value of the data type UDINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnUdint : HRESULTVAR_INPUT    value : UDINT;END_VAR

4.1.13 OnUlintThis callback method is triggered if a value of the data type ULINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnUlint : HRESULTVAR_INPUT    value : ULINT;END_VAR

4.2 ITcJsonSaxValues

4.2.1 OnBoolValueThis callback method is triggered if a value of the data type BOOL was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnBoolValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : BOOL;END_VAR

Page 92: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Interfaces

TE100092 Version: 1.7

4.2.2 OnDintValueThis callback method is triggered if a value of the data type DINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnDintValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : DINT;END_VAR

4.2.3 OnLintValueThis callback method is triggered if a value of the data type LINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnLintValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : LINT;END_VAR

4.2.4 OnLrealValueThis callback method is triggered if a value of the data type LREAL was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnLrealValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : LREAL;END_VAR

4.2.5 OnNullValueThis callback method is triggered if a NULL value was found at the position of the SAX reader. The SAXparsing procedure is aborted by setting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnNull : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;END_VAR

4.2.6 OnStringValueThis callback method is triggered if a value of the data type STRING was found at the position of the SAXreader. The input/output parameter value contains the value found. The SAX parsing procedure is abortedby setting the return value HRESULT to S_FALSE.

Page 93: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Interfaces

TE1000 93Version: 1.7

SyntaxMETHOD OnStringValue : HRESULTVAR_IN_OUT CONSTANT    value : STRING;END_VARVAR_INPUT    len : UDINT;    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;END_VAR

4.2.7 OnUdintValueThis callback method is triggered if a value of the data type UDINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnUdintValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : UDINT;END_VAR

4.2.8 OnUlintValueThis callback method is triggered if a value of the data type ULINT was found at the position of the SAXreader. The input parameter value contains the value found. The SAX parsing procedure is aborted bysetting the return value HRESULT to S_FALSE.

SyntaxMETHOD OnUlintValue : HRESULTVAR_INPUT    level : UDINT;    infos : POINTER TO TcJsonLevelInfo;    value : ULINT;END_VAR

Page 94: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE100094 Version: 1.7

5 Samples

5.1 Tc3JsonXmlSampleJsonDataTypeSample of the automatic conversion of structures into a JSON message

This sample illustrates how a data structure can be converted into a JSON message (and vice versa). In theconversion the layout of a structure is converted one-to-one into a corresponding JSON equivalent.Additional metadata can be created via PLC attributes on the member variables of the structure.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/3664376331.zip

Layout of the data structure to be convertedTYPE ST_Values :STRUCT

  {attribute 'Unit' := 'm/s'}  {attribute 'DisplayName' := 'Speed'}  Sensor1 : REAL;

  {attribute 'Unit' := 'V'}  {attribute 'DisplayName' := 'Voltage'}  Sensor2 : DINT;

  {attribute 'Unit' := 'A'}  {attribute 'DisplayName' := 'Current'}  Sensor3 : DINT;

END_STRUCTEND_TYPE

Declaration rangePROGRAM MAINVAR  dtTimestamp    : DATE_AND_TIME := DT#2017-04-04-12:42:42;  fbJson         : FB_JsonSaxWriter;  fbJsonDataType : FB_JsonReadWriteDataType;  sJsonDoc       : STRING(255);   sJsonDoc2      : STRING(2000);   stValues       : ST_Values;END_VAR

Implementation range

Two ways of generating the JSON message are shown, starting with the instance fbJson of the functionblock FB_JsonSaxWriter. The GetDocument() method can be used with a JSON message with no more than255 characters. However, the CopyDocument() method must be used with larger JSON messages.fbJson.ResetDocument();fbJson.StartObject();fbjson.AddKeyDateTime('Timestamp', dtTimestamp);fbJsonDataType.AddJsonKeyValueFromSymbol(fbJson, 'Values', 'ST_Values', SIZEOF(stValues), ADR(stValues));fbJsonDataType.AddJsonKeyPropertiesFromSymbol(fbJson, 'MetaData', 'ST_Values', 'Unit|DisplayName');fbJson.EndObject();sJsonDoc := fbJson.GetDocument();fbJson.CopyDocument(sJsonDoc2, SIZEOF(sJsonDoc2));

Resulting JSON message{  "Timestamp": "2017-04-10T17:35:49",  "Values": {    "Sensor1": 0.0,    "Sensor2": 0,    "Sensor3": 0  },  "MetaData": {    "Sensor1": {

Page 95: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE1000 95Version: 1.7

      "Unit": "m/s",      "DisplayName": "Speed"    },    "Sensor2": {      "Unit": "V",      "DisplayName": "Voltage"    },    "Sensor3": {      "Unit": "A",      "DisplayName": "Current"    }  }}

Alternative

As an alternative, the method AddJsonValueFromSymbol() can also be used to generate a JSON formatdirectly from a data structure.fbJson.ResetDocument();fbJsonDataType.AddJsonValueFromSymbol(fbJson, 'ST_Values', SIZEOF(stValues), ADR(stValues));sJsonDoc := fbJson.GetDocument();fbJson.CopyDocument(sJsonDoc2, SIZEOF(sJsonDoc2));

The resulting JSON object looks like this:{  "Sensor1": 0.0,  "Sensor2": 0,  "Sensor3": 0}

Conversion of a JSON message back to a data structure

The above samples show how a JSON object can be generated from a data structure in a simple manner.There is also a corresponding method in the Tc3_JsonXml library for the reverse process, i.e. the extractionof values from a (received) JSON object back into a data structure. This application is made possible bycalling the method SetSymbolFromJson().fbJsonDataType.SetSymbolFromJson(someJson, 'ST_Values', SIZEOF(stValuesReceive),ADR(stValuesReceive));

The string variable sJsonDoc2 contains the JSON object, which is transferred into the structure instancestValuesReceive by calling the method.

Target data structureThe target data structure must match the structure of the JSON document. Otherwise SetSymbol-FromJson() returns FALSE.

5.2 Tc3JsonXmlSampleJsonSaxReaderSample of the parsing of JSON documents via SAX Reader

This sample illustrates how a JSON message can be run through programmatically. The function blockFB_JsonSaxReader is used as the basis.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/3664750475.zip

Declaration rangePROGRAM MAINVAR  fbJson     : FB_JsonSaxReader;  pJsonParse : JsonSaxHandler;  sJsonDoc   : STRING(255) := '{"Values":{"Timestamp":"2017-04-04T12:42:42","Sensor1":42.42,"Sensor2":42}}';END_VAR

Page 96: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE100096 Version: 1.7

Implementation range

Through the calling of the Parse() method, the transfer of the JSON message as a STRING and the interfacepointer to a function block instance that implements the interface ItcJsonSaxHandler, the SAX Reader isactivated and the corresponding callback methods are run through.fbJson.Parse(sJson := sJsonDoc, ipHdl := pJsonParse);

Callback methods

The callback methods are called on the instance of the function block that implements the interfaceItcJsonSaxHandler. Each callback method represents a "found" element in the JSON message. Forexample, the callback method OnStartObject() is called as soon as an opening curly bracket has beendetected. According to the example JSON message mentioned above, therefore, the following callbackmethods are run through in this order:

1. OnStartObject(), due to the first opening curly bracket2. OnKey(), due to the property "Values"3. OnStartObject(), due to the second opening curly bracket4. OnKey(), due to the property "Timestamp"5. OnString(), due to the value of the property "Timestamp"6. OnKey(), due to the property "Sensor1"7. OnLreal(), due to the value of the property "Sensor1"8. OnKey(), due to the property "Sensor2"9. OnUdint(), due to the value of the property "Sensor2"

10. OnEndObject(), due to the first closing curly bracket11. OnEndObject(), due to the second closing curly bracket

Within the callback methods the current state is defined and saved via an instance of the enumE_JsonStates. This can also be used to determine whether the JSON message is valid. For example, if thecallback method OnLreal() is called and the state is not the expected State 70 (JSON_STATE_ONLREAL),the return value S_FALSE can be returned to the method. The SAX Reader then automatically cancels thefurther processing.

5.3 Tc3JsonXmlSampleJsonSaxWriterSample of the creation of JSON documents via SAX Writer

This sample illustrates how a JSON message can be created over the DAX mechanism. The function blockFB_JsonSaxWriter is used as the basis.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/3664753419.zip

Declaration rangePROGRAM MAINVAR  dtTimestamp : DATE_AND_TIME := DT#2017-04-04-12:42:42;  fbJson      : FB_JsonSaxWriter;  sJsonDoc    : STRING(255);END_VAR

Implementation range

The SAX mechanism runs sequentially through the JSON document to be created, i.e. the correspondingelements are run though and created one after the other.fbJson.StartObject();fbJson.AddKey('Timestamp');fbJson.AddDateTime(dtTimestamp);fbJson.AddKey('Values');fbJson.StartObject();fbJson.AddKey('Sensor1');fbJson.AddReal(42.42);

Page 97: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE1000 97Version: 1.7

fbJson.AddKey('Sensor2');fbJson.AddDint(42);fbJson.AddKey('Sensor3');fbJson.AddBool(TRUE);fbJson.EndObject();fbJson.EndObject();sJsonDoc := fbJson.GetDocument();fbJson.ResetDocument();

Resulting JSON message{  "Timestamp": "2017-04-04T12:42:42",  "Values": {    "Sensor1": 42.42,    "Sensor2": 42,    "Sensor3": true  }}

5.4 Tc3JsonXmlSampleJsonDomReaderThis sample illustrates how a JSON message can be run through programmatically on the basis of DOM.The function block FB_JsonDomParser is used as the basis.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/3916597387.zip

Declaration rangePROGRAM MAINVAR  fbJson     : FB_JsonDomParser;  jsonDoc    : SJsonValue;  jsonProp   : SJsonValue;  jsonValue  : SJsonValue;  bHasMember : BOOL;  sMessage   : STRING(255) := '{"serialNumber":"G030PT028191AC4R","batteryVoltage":"1547mV","clickType":"SINGLE"}';  stReceivedData : ST_ReceivedData;END_VAR

Implementation range

The JSON message is loaded into the DOM tree using the ParseDocument() method. You can subsequentlycheck whether it contains a certain property using the HasMember() method. The FindMember() methodselects the property. The GetString() method extracts its value.jsonDoc := fbJson.ParseDocument(sMessage);bHasMember := fbJson.HasMember(jsonDoc, 'serialNumber');IF (bHasMember) THEN  bHasMember := FALSE;  jsonProp := fbJson.FindMember(jsonDoc, 'serialNumber');  stReceivedData.serialNumber := fbJson.GetString(jsonProp);END_IF

bHasMember := fbJson.HasMember(jsonDoc, 'batteryVoltage');IF (bHasMember) THEN  bHasMember := FALSE;  jsonProp := fbJson.FindMember(jsonDoc, 'batteryVoltage');  stReceivedData.batteryVoltage := fbJson.GetString(jsonProp);END_IF

bHasMember := fbJson.HasMember(jsonDoc, 'clickType');IF (bHasMember) THEN  bHasMember := FALSE;  jsonProp := fbJson.FindMember(jsonDoc, 'clickType');  stReceivedData.clickType := fbJson.GetString(jsonProp);END_IF

The use of the method HasMember() is not absolutely necessary, since the method FindMember() alreadyreturns 0 if a property was not found. The code shown above can also be implemented as follows:

Page 98: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE100098 Version: 1.7

jsonDoc := fbJson.ParseDocument(sMessage);

jsonProp := fbJson.FindMember(jsonDoc, 'serialNumber');IF (jsonProp <> 0) THEN  stReceivedData.serialNumber := fbJson.GetString(jsonProp);END_IF

jsonProp := fbJson.FindMember(jsonDoc, 'batteryVoltage');IF (jsonProp <> 0) THEN  stReceivedData.batteryVoltage := fbJson.GetString(jsonProp);END_IF

jsonProp := fbJson.FindMember(jsonDoc, 'clickType');IF (jsonProp <> 0) THEN  stReceivedData.clickType := fbJson.GetString(jsonProp);END_IF

Nested JSON objects

The approach is similar with nested JSON objects. Since the entire document is located in the DOM, it issimple to navigate. Let's take a JSON object that looks like this:sMessage : STRING(255) := '{"Values":{"serial":"G030PT028191AC4R"}}';

The property we are looking for is located in the sub-object "Values". The following code shows how toextract the property.jsonDoc := fbJson.ParseDocument(sMessage);bHasMember := fbJson.HasMember(jsonDoc, 'Values');IF (bHasMember) THEN  bHasMember := FALSE;  jsonProp := fbJson.FindMember(jsonDoc, 'Values');  IF jsonProp <> 0 THEN    jsonSerial := fbJson.FindMember(jsonProp, 'serial');    stReceivedData.serialNumber := fbJson.GetString(jsonSerial);  END_IFEND_IF

5.5 Tc3JsonXmlSampleXmlDomReaderThis sample illustrates how an XML document can be processed programmatically based on DOM. Thefunction block FB_XmlDomParser is used as a basis.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/5529225227.zip

Declaration rangePROGRAM MAINVAR  fbXml : FB_XmlDomParser;  xmlDoc : SXmlNode;  xmlMachines : SXmlNode;  xmlMachine1 : SXmlNode;  xmlMachine2 : SXmlNode;  xmlIterator : SXmlIterator;  xmlMachineNode : SXmlNode;  xmlMachineNodeValue : STRING;  xmlMachineAttributeRef : SXmlAttribute;  xmlMachine1Attribute : SXmlAttribute;  xmlMachine2Attribute : SXmlAttribute;  sMachine1Name : STRING;  sMachine2Name : STRING;  nMachineAttribute : DINT;  nMachine1Attribute : DINT;  nMachine2Attribute : DINT;  sMessageToParse : STRING(255) := '<Machines><Machine Type="1" Test="3">Wilde Nelli</Machine><Machine Type="2">Huber8</Machine></Machines>';END_VAR

Implementation range

The implementation section shows various options for parsing an XML document.

Page 99: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE1000 99Version: 1.7

(* Load XML content *)xmlDoc := fbXml.ParseDocument(sMessageToParse);

(* Parse XML nodes - Option 1 *)xmlMachines := fbXml.ChildByName(xmlDoc, 'Machines');xmlMachine1 := fbXml.ChildByAttribute(xmlMachines, 'Type', '1');xmlMachine2 := fbXml.ChildByAttributeAndName(xmlMachines, 'Type', '2', 'Machine');

(* Parse XML nodes - Option 2 *)xmlMachines := fbXml.ChildByName(xmlDoc, 'Machines');xmlMachineNode := fbXml.Children(xmlMachines, xmlIterator);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineNode := fbXml.Node(xmlIterator);  xmlMachineNodeValue := fbXml.NodeText(xmlMachineNode);  xmlMachineNode := fbXml.Children(xmlMachines, xmlIterator);END_WHILE

(* Parse XML nodes - Option 3 *)xmlMachines := fbXml.ChildByName(xmlDoc, 'Machines');xmlIterator := fbXml.Begin(xmlMachines);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineNode := fbXml.Node(xmlIterator);  xmlMachineNodeValue := fbXml.NodeText(xmlMachineNode);  xmlIterator := fbXml.Next(xmlIterator);  xmlIterator := fbXml.End(xmlMachines);END_WHILE

(* Parse XML attributes - Option 1*)xmlMachine1Attribute := fbXml.Attribute(xmlMachine1, 'Type');xmlMachine2Attribute := fbXml.Attribute(xmlMachine2, 'Type');

(* Parse XML attributes - Option 2*)xmlIterator := fbXml.AttributeBegin(xmlMachine1);WHILE NOT fbXml.IsEnd(xmlIterator) DO  xmlMachineAttributeRef := fbXml.AttributeFromIterator(xmlIterator);  nMachineAttribute := fbXml.AttributeAsInt(xmlMachineAttributeRef);  xmlIterator := fbXml.Next(xmlIterator);END_WHILE

(* Retrieve node values *)sMachine1Name := fbXml.NodeText(xmlMachine1);sMachine2Name := fbXml.NodeText(xmlMachine2);

(* Retrieve attribute values *)nMachine1Attribute := fbXml.AttributeAsInt(xmlMachine1Attribute);nMachine2Attribute := fbXml.AttributeAsInt(xmlMachine2Attribute);

5.6 Tc3JsonXmlSampleXmlDomWriterThis sample illustrates how an XML document can be created programmatically based on DOM. Thefunction block FB_XmlDomParser is used as a basis.

Download: https://infosys.beckhoff.com/content/1033/TcPlcLib_Tc3_JsonXml/Resources/zip/5529228299.zip

Declaration rangePROGRAM MAINVAR  fbXml : FB_XmlDomParser;  objRoot : SXmlNode;  objMachines : SXmlNode;  objMachine : SXmlNode;  objControllers : SXmlNode;  objController : SXmlNode;  objAttribute : SXmlAttribute;  sXmlString : STRING(1000);  bCreate : BOOL := FALSE;  bSave : BOOL := TRUE;  nLength : UDINT;  newAttr : SXmlAttribute;END_VAR

Implementation range

The implementation section shows various options for creating an XML document.

Page 100: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Samples

TE1000100 Version: 1.7

IF bCreate THEN  (* Create an empty XML document *)  objRoot := fbXml.GetDocumentNode();

  (* Create a new XML node 'Machines' and add to the empty document *)  objMachines := fbXml.AppendNode(objRoot, 'Machines');    (* Create a new XML node 'Machine' and add an attribute to this node. Append node to 'Machines' *)  objMachine := fbXml.AppendNode(objMachines, 'Machine');  objAttribute := fbXml.AppendAttribute(objMachine, 'Name', 'Wilde Nelli');

  (* Create a new XML node 'Controllers' and add to the 'Machine' node *)  objControllers := fbXml.AppendNode(objMachine, 'Controllers');

  (* Create a new XML node 'Controller' and add some attributes. Append node to 'Controllers'. *)  objController := fbXml.AppendChild(objControllers, 'Controller', 'CX5120', FALSE);  objAttribute := fbXml.AppendAttribute(objController, 'Type', 'EPC');  objAttribute := fbXml.AppendAttribute(objController, 'OS', 'Windows Embedded Compact 7');

  (* Create a new XML node 'Controller' and add some attributes. Append node to 'Controllers'. *)  objController := fbXml.AppendChild(objControllers, 'Controller', 'CX2040', FALSE);  objAttribute := fbXml.AppendAttribute(objController, 'Type', 'EPC');  objAttribute := fbXml.AppendAttribute(objController, 'OS', 'Windows Embedded Standard 7');

  (* Create a new XML node 'Controller' and add some attributes. Append node to 'Controllers'. *)  objController := fbXml.AppendChild(objControllers, 'Controller', 'C6015', FALSE);  objAttribute := fbXml.AppendAttribute(objController, 'Type', 'IPC');  objAttribute := fbXml.AppendAttribute(objController, 'OS', 'Windows 10 IoT Enterprise');

  (* Create a new XML node 'Machine' and add an attribute to this node. Append node to 'Machines' *)  objMachine := fbXml.AppendNode(objMachines, 'Machine');  objAttribute := fbXml.AppendAttribute(objMachine, 'Name', 'Stanze Oscar');    (* Create a new XML node 'Controllers' and add to the 'Machine' node *)  objControllers := fbXml.AppendNode(objMachine, 'Controllers');

  (* Create a new XML node 'Controller' and add some attributes. Append node to 'Controllers'. *)  objController := fbXml.AppendChild(objControllers, 'Controller', 'C6017', FALSE);  objAttribute := fbXml.AppendAttribute(objController, 'Type', 'IPC');  objAttribute := fbXml.AppendAttribute(objController, 'OS', 'Windows 10 IoT Enterprise');  newAttr := fbXml.InsertAttribute(objController, objAttribute, 'AddAttribute');  fbXml.SetAttribute(newAttr, 'Hola');

  (* Retrieve XML document and store in a variable of data type STRING(1000) *)  nLength := fbXml.CopyDocument(sXmlString, SIZEOF(sXmlString));  bCreate := FALSE;END_IF

Page 101: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Support and Service

TE1000 101Version: 1.7

6 Support and ServiceBeckhoff and their partners around the world offer comprehensive support and service, making available fastand competent assistance with all questions related to Beckhoff products and system solutions.

Beckhoff's branch offices and representatives

Please contact your Beckhoff branch office or representative for local support and service on Beckhoffproducts!

The addresses of Beckhoff's branch offices and representatives round the world can be found on her internetpages:http://www.beckhoff.com

You will also find further documentation for Beckhoff components there.

Beckhoff Headquarters

Beckhoff Automation GmbH & Co. KG

Huelshorstweg 2033415 VerlGermany

Phone: +49(0)5246/963-0Fax: +49(0)5246/963-198e-mail: [email protected]

Beckhoff Support

Support offers you comprehensive technical assistance, helping you not only with the application ofindividual Beckhoff products, but also with other, wide-ranging services:

• support• design, programming and commissioning of complex automation systems• and extensive training program for Beckhoff system components

Hotline: +49(0)5246/963-157Fax: +49(0)5246/963-9157e-mail: [email protected]

Beckhoff Service

The Beckhoff Service Center supports you in all matters of after-sales service:

• on-site service• repair service• spare parts service• hotline service

Hotline: +49(0)5246/963-460Fax: +49(0)5246/963-479e-mail: [email protected]

Page 102: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback
Page 103: Manual PLC Lib: Tc3 JsonXml - Beckhoff Automation · 2019. 11. 19. · the data stream. A SAX parser is therefore also referred to as an event-based parser. The events occurring (callback

Beckhoff Automation GmbH & Co. KGHülshorstweg 2033415 VerlGermanyPhone: +49 5246 [email protected]

More Information: www.beckhoff.com/twincat/te1000/