Skip to content

Step 3: Setup Visual Studio to edit OPC UA ModelDesign files

Last updated on September 29, 2020


Set up Visual Studio to edit OPC UA ModelDesign files with the help of XSD files provided by the OPC Foundation.

This Post is part of the OPC UA Information Model Tutorial.


Alternative

Alternative ModelDesign editors are evaluated in Alternative OPC UA ModelDesign Editors

Note

Do not confuse Visual Studio (VS) with Visual Studio Code (VSC)! While VS is a full-feature IDE, VSC is a very extensible code editor with many plugins such as https://marketplace.visualstudio.com/items?itemName=rogalmic.vscode-xml-complete. At the moment (March 2020) VSC (including plugins) does not offer all conveniences of VS when it comes to XML editing. Use VS2019 or later.

The following content is mainly based on the Microsoft online documentation of Visual Studio 2019 XML Tools https://docs.microsoft.com/en-us/visualstudio/xml-tools/xml-tools-in-visual-studio?view=vs-2019

Open the ModelDesign file

Download the ModelDesign file associated to this tutorial from Github:

https://github.com/Pro/opcua-modeling-tutorial

More specifically, download the FooFltModel.xml and FooFltModel.csv files.

Open Visual Studio without a Project File by just clicking on Continue without code and then choose the downloaded Model.xml file.

Associate XSD files with the XML file

XSD files define which attributes are valid for XML elements. VS2019 uses them for syntax checking and auto-completion in XML files. Use the schemas provided by https://github.com/OPCFoundation/UA-ModelCompiler branch v1.04.

If you followed Step 2: Setup UA-ModelCompiler with Visual Studio, you have these files in your local repository.

The XSD files of each repository are listed explicitly below to help you locate them (feel free to scroll past them for now)

# johndoe@winpc MINGW64 /c/FLT_SW/UA-ModelCompiler ((8817477...))
find . -name *.xsd
# ./Core/Schema/ApplicationConfiguration.xsd
# ./Core/Schema/Opc.Ua.Gds.Types.xsd
# ./Core/Schema/Opc.Ua.Types.xsd
# ./Core/Schema/OPCBinarySchema.xsd
# ./Core/Schema/SecuredApplication.xsd
# ./Core/Schema/UANodeSet.xsd
# ./Core/Schema/UAVariant.xsd
# ./Core/Stack/Generated/Opc.Ua.Adi.Types.xsd
# ./Core/Stack/Generated/Opc.Ua.Di.Types.xsd
# ./Core/Stack/Generated/Opc.Ua.Types.xsd
# ./Core/Stack/Generated/OPCBinarySchema.xsd
# ./Core/Stack/Generated/SecuredApplication.xsd
# ./Core/Stack/Generated/UANodeSet.xsd
# ./Core/Types/Schemas/OPCBinarySchema.xsd
# ./ModelCompiler/StackGenerator/DataTypes/Templates/XmlSchema/BuiltInTypes.xsd
# ./ModelCompiler/StackGenerator/Validators/UA Type Dictionary.xsd
# ./ModelCompiler/StackGenerator/Validators/Xml/BuiltInTypes.xsd
# ./ModelCompiler/Templates/XmlSchema/BuiltInTypes.xsd
# ./ModelCompiler/UA Model Design.xsd
# ./Published/ADI/Opc.Ua.Adi.Types.xsd
# ./Published/DI/Opc.Ua.Di.Types.xsd
# ./Published/FDI/Opc.Ua.Fdi5.Types.xsd
# ./Published/FDI/Opc.Ua.Fdi7.Types.xsd
# ./Published/GDS/Opc.Ua.Gds.Types.xsd
# ./Published/ISA-95/OPC.ISA95.Types.xsd
# ./Published/MTConnect/Opc.Ua.MTConnect.Types.xsd
# ./Published/PLCopen/Opc.Ua.Plc.Types.xsd
# ./Published/Schema/Opc.Ua.Types.xsd
# ./Published/Schema/OPCBinarySchema.xsd
# ./Published/Schema/SecuredApplication.xsd
# ./Published/Schema/UANodeSet.xsd
# ./Published/Sercos/Sercos.Types.xsd
# ./Published/TMC/Opc.Ua.TMC.NodeSet2.xsd

Determine the XSD files relevant to the ModelDesign file to be edited.

FooFltModel.xml holds the following text

<ModelDesign
  xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:ua="http://opcfoundation.org/UA/"
  xmlns:FooZbrFlt="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  TargetNamespace="https://new.foo.com/zebra-compression/flattening-and-subspacefolding/UA/"
  TargetVersion="0.9.0"
  TargetPublicationDate="2020-05-01T00:00:00Z"
  xmlns="http://opcfoundation.org/UA/ModelDesign.xsd">

The definitions related to w3.org are standard and already included in VS2019 (you will see that when editing the XML document properties).

That leaves

  • xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
  • xmlns:ua="http://opcfoundation.org/UA/"
  • xmlns="http://opcfoundation.org/UA/ModelDesign.xsd

The files to providing those namespaces are

  • UA-ModelCompiler/ModelCompiler/UA Model Design.xsd
  • UA-ModelCompiler/Core/Schema/Opc.Ua.Types.xsd or UA-ModelCompiler/Published/Schema/Opc.Ua.Types.xsd (both of them are ident except for a copyright notice and whitespace)
Note

Quite often you will find conflicting XSD files and it takes some research and trial & error to identify the most suitable XSD file. Ensuring a complete, up-to-date and correct selection of XSD files is a crucial task.

To locate XSD files of other namespaces, search in the git repository of the OPCFoundation for any XSD file, that defines the desired targetNamespace.

# johndoe@winpc MINGW64 /c/FLT_SW
ls -al
# total 28
# drwxr-xr-x 1 johndoe 1049089 0 Mar 17 12:04 ./
# drwxr-xr-x 1 johndoe 1049089 0 Mar 17 16:59 ../
# drwxr-xr-x 1 johndoe 1049089 0 Mar 12 13:59 UA-ModelCompiler/
# drwxr-xr-x 1 johndoe 1049089 0 Mar 18 07:12 Wiki/
# 
# johndoe@winpc MINGW64 /c/FLT_SW
grep -r --include \*.xsd targetNamespace | grep ModelDesign
# UA-ModelCompiler/ModelCompiler/UA Model Design.xsd: targetNamespace="http://opcfoundation.org/UA/ModelDesign.xsd"

# johndoe@winpc MINGW64 /c/FLT_SW
grep -r --include \*.xsd targetNamespace | grep 2008
# UA-ModelCompiler/Core/Schema/Opc.Ua.Types.xsd:  targetNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd"
# UA-ModelCompiler/Core/Schema/UAVariant.xsd:  targetNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd"
# UA-ModelCompiler/Core/Stack/Generated/Opc.Ua.Types.xsd:  targetNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd"
# UA-ModelCompiler/Published/Schema/Opc.Ua.Types.xsd:  targetNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd"
# UA-ModelCompiler/Published/TMC/Opc.Ua.TMC.NodeSet2.xsd:<xs:schema elementFormDefault="qualified" targetNamespace="http://opcfoundation.org/UA/TMC/Types.xsd" xmlns:tns="http://opcfoundation.org/UA/TMC/Types.xsd" xmlns:ua="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
# UA-ModelCompiler/Published/Schema/Opc.Ua.Types.xsd:  targetNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd"
# UA-ModelCompiler/Published/TMC/Opc.Ua.TMC.NodeSet2.xsd:<xs:schema elementFormDefault="qualified" targetNamespace="http://opcfoundation.org/UA/TMC/Types.xsd" xmlns:tns="http://opcfoundation.org/UA/TMC/Types.xsd" xmlns:ua="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">

The least invasive but most explicit way to associate the XSD files with your XML file, is to open all XSD files relevant to your model in VS2019. This approach allows for quick review of the relevant XSD files as well.

Note

The Microsoft online tutorial recommends to edit the XML document properties. Keep in mind that those settings will be lost once VS2019 is restarted (unless the XML file is part of a VS solution I guess).

There are several ways to associate XSD files with XML files, mentioned in https://docs.microsoft.com/en-us/visualstudio/xml-tools/xml-document-validation?view=vs-2019

Use VS2019 suggestions and auto-completion

By now, you should have the ModelDesign file and the relevant XSD files open in VS2019. The tabs in the screenshot do not represent the actual XSD files required.

Type inside the ModelDesign file to get valid suggestions and auto-completion (based on the XSD files) from VS2019.

Read more about the VS2019 code completion features at: https://docs.microsoft.com/en-us/visualstudio/xml-tools/xml-editor-intellisense-features?view=vs-2019

So far, XSD files were used indirectly via the auto-completion feature of VS2019. Direct inspection of XSD files is possible too, and helpful to explore them.

When selecting a schema file (note the [Design] tag next to the filename in the tab label), several views are available:

  • Start View
  • Content View
  • Graph View

The Start View is shown below (indicated with the blue arrow)

To navigate the views, it’s useful to know that you can return to the Start View any time with right clicking in the XSD file and select View Designer.

Using Types.xsd as example, the file is opened in different views at the same time to demonstrate the relation ship between the different graphical/textual representation in the views.

Published inInformation Modeling

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.