OPC Studio User's Guide and Reference
TryParseRelative Method (UABrowsePathParser)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Navigation.Parsing Namespace > UABrowsePathParser Class : TryParseRelative Method
The string containing the relative browse path to be parsed.

The value of this parameter cannot be null (Nothing in Visual Basic).

OpcLabs.EasyOpc.UA.Navigation.UABrowsePathElementCollection. If successful, an original collection of browse path elements, expanded by elements corresponding to the input string.

Because the OpcLabs.EasyOpc.UA.Navigation.UABrowsePathElementCollection has an implicit conversion from OpcLabs.EasyOpc.UA.AddressSpace.UAQualifiedNameCollection, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UAQualifiedNameCollection (containing a sequence of qualified names, assumed to form a relative browse path using "any hierarchical" forward references) in place of this parameter, and the corresponding OPC UA browse path element collection will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromUAQualifiedNameCollection static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Attempts to parse a string containing a relative browse path.
Syntax
'Declaration
 
<CanBeNullAttribute()>
<PureAttribute()>
Public Function TryParseRelative( _
   ByVal value As String, _
   ByVal browsePathElementCollection As UABrowsePathElementCollection _
) As IStringParsingError
'Usage
 
Dim instance As UABrowsePathParser
Dim value As String
Dim browsePathElementCollection As UABrowsePathElementCollection
Dim value As IStringParsingError
 
value = instance.TryParseRelative(value, browsePathElementCollection)

Parameters

value
The string containing the relative browse path to be parsed.

The value of this parameter cannot be null (Nothing in Visual Basic).

browsePathElementCollection
OpcLabs.EasyOpc.UA.Navigation.UABrowsePathElementCollection. If successful, an original collection of browse path elements, expanded by elements corresponding to the input string.

Because the OpcLabs.EasyOpc.UA.Navigation.UABrowsePathElementCollection has an implicit conversion from OpcLabs.EasyOpc.UA.AddressSpace.UAQualifiedNameCollection, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UAQualifiedNameCollection (containing a sequence of qualified names, assumed to form a relative browse path using "any hierarchical" forward references) in place of this parameter, and the corresponding OPC UA browse path element collection will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromUAQualifiedNameCollection static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Return Value

Returns null if successful; otherwise, some OpcLabs.BaseLib.IStringParsingError indicating the reason of the failure.

This method can return null (Nothing in Visual Basic).

Remarks

This method is pure, i.e. it does not have observable side effects.

Example
// Attempts to parse a relative OPC-UA browse path and displays its elements.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.BaseLib;
using OpcLabs.EasyOpc.UA.Navigation;
using OpcLabs.EasyOpc.UA.Navigation.Parsing;

namespace UACommonDocExamples._UABrowsePathParser
{
    class TryParseRelative
    {
        public static void Main1()
        {
            var browsePathElements = new UABrowsePathElementCollection();

            var browsePathParser = new UABrowsePathParser();
            IStringParsingError stringParsingError = browsePathParser.TryParseRelative("/Data.Dynamic.Scalar.CycleComplete", browsePathElements);

            // Display results
            if (!(stringParsingError is null))
            {
                Console.WriteLine("*** Error: {0}", stringParsingError);
                return;
            }

            foreach (UABrowsePathElement browsePathElement in browsePathElements)
                Console.WriteLine(browsePathElement);

            // Example output:
            // /Data
            // .Dynamic
            // .Scalar
            // .CycleComplete        
        }
    }
}
' Attempts to parse a relative OPC-UA browse path and displays its elements.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports System
Imports OpcLabs.BaseLib
Imports OpcLabs.EasyOpc.UA.Navigation
Imports OpcLabs.EasyOpc.UA.Navigation.Parsing

Namespace _UABrowsePathParser
    Friend Class TryParseRelative
        Public Shared Sub Main1()
            Dim browsePathElements = New UABrowsePathElementCollection()

            Dim browsePathParser = New UABrowsePathParser()
            Dim stringParsingError As IStringParsingError = browsePathParser.TryParseRelative("/Data.Dynamic.Scalar.CycleComplete", browsePathElements)

            ' Display results
            If Not stringParsingError Is Nothing Then
                Console.WriteLine("*** Error: {0}", stringParsingError)
                Exit Sub
            End If

            For Each browsePathElement As UABrowsePathElement In browsePathElements
                Console.WriteLine(browsePathElement)
            Next browsePathElement

            ' Example output:
            ' /Data
            ' .Dynamic
            ' .Scalar
            ' .CycleComplete
        End Sub
    End Class
End Namespace
// Attempts to parse a relative OPC-UA browse path and displays its elements.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure TryParseRelative.Main;
var
  BrowsePathElement: _UABrowsePathElement;
  BrowsePathElements: _UABrowsePathElementCollection;
  BrowsePathParser: OpcLabs_EasyOpcUA_TLB._UABrowsePathParser;
  Count: Cardinal;
  Element: OleVariant;
  ElementEnumerator: IEnumVariant;
  StringParsingError: _StringParsingError;
begin
  BrowsePathElements := CoUABrowsePathElementCollection.Create;

  BrowsePathParser := CoUABrowsePathParser.Create;
  StringParsingError := BrowsePathParser.TryParseRelative('/Data.Dynamic.Scalar.CycleComplete', BrowsePathElements);

  // Display results
  if StringParsingError <> nil then
  begin
    WriteLn('*** Error: ', StringParsingError.ToString);
    Exit;
  end;

  ElementEnumerator := BrowsePathElements.GetEnumerator;
  while (ElementEnumerator.Next(1, Element, Count) = S_OK) do
  begin
    BrowsePathElement := IUnknown(Element) as _UABrowsePathElement;
    WriteLn(BrowsePathElement.ToString);
  end;

  // Example output:
  // /Data
  // .Dynamic
  // .Scalar
  // .CycleComplete

end;
// Attempts to parse a relative OPC-UA browse path and displays its elements.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

$BrowsePathElements = new COM("OpcLabs.EasyOpc.UA.Navigation.UABrowsePathElementCollection");

$BrowsePathParser = new COM("OpcLabs.EasyOpc.UA.Navigation.Parsing.UABrowsePathParser");

$StringParsingError = $BrowsePathParser->TryParseRelative("/Data.Dynamic.Scalar.CycleComplete", $BrowsePathElements);

// Display results
if (!is_null($StringParsingError)) {
    printf("*** Error: %s\n", $StringParsingError);
    exit();
}

printf("StartingNodeId: %s\n", $BrowsePath->StartingNodeId);

printf("Elements:\n");

for ($i = 0; $i < $BrowsePathElements->Count; $i++)
{
    printf("%s\n", $BrowsePathElements[$i]);
}

// Example output:
// /Data
// .Dynamic
// .Scalar
// .CycleComplete
REM Attempts to parse a relative OPC-UA browse path and displays its elements.
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.

Private Sub TryParseRelative_Main_Command_Click()
    OutputText = ""
    
    Dim BrowsePathElements As New UABrowsePathElementCollection
    
    Dim BrowsePathParser As New UABrowsePathParser

    Dim stringParsingError As stringParsingError
    Set stringParsingError = BrowsePathParser.TryParseRelative("/Data.Dynamic.Scalar.CycleComplete", BrowsePathElements)
    
    ' Display results
    If Not stringParsingError Is Nothing Then
        OutputText = OutputText & "*** Error: " & stringParsingError & vbCrLf
        Exit Sub
    End If
    
    Dim BrowsePathElement: For Each BrowsePathElement In BrowsePathElements
        OutputText = OutputText & BrowsePathElement & vbCrLf
    Next

    ' Example output:
    '/Data
    '.Dynamic
    '.Scalar
    '.CycleComplete
End Sub
# Attempts to parse a relative OPC-UA browse path and displays its elements.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.Navigation import *
from OpcLabs.EasyOpc.UA.Navigation.Parsing import *


browsePathElements = UABrowsePathElementCollection()

browsePathParser = UABrowsePathParser()
stringParsingError = browsePathParser.TryParseRelative('/Data.Dynamic.Scalar.CycleComplete', browsePathElements)

# Display results.
if stringParsingError is not None:
    print('*** Error: ', stringParsingError, sep='')
    exit()

for browsePathElement in browsePathElements:
    print(browsePathElement)

print()
print('Finished.')
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also