OPC Studio User's Guide and Reference
TryParse(String,UABrowsePath) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Navigation.Parsing Namespace > UABrowsePathParser Class : TryParse(String,UABrowsePath) Method
The string containing the absolute browse path to be parsed.

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

OpcLabs.EasyOpc.UA.Navigation.UABrowsePath. If successful, the browse path object corresponding to the input string.

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

Attempts to parse a string containing an absolute browse path.
Syntax
'Declaration
 
<CanBeNullAttribute()>
<PureAttribute()>
Public Function TryParse( _
   ByVal value As String, _
   ByRef browsePath As UABrowsePath _
) As IStringParsingError
'Usage
 
Dim instance As UABrowsePathParser
Dim value As String
Dim browsePath As UABrowsePath
Dim value As IStringParsingError
 
value = instance.TryParse(value, browsePath)
[CanBeNull()]
[Pure()]
public IStringParsingError TryParse( 
   string value,
   out UABrowsePath browsePath
)
[CanBeNull()]
[Pure()]
public:
IStringParsingError^ TryParse( 
   String^ value,
   [Out] UABrowsePath^ browsePath
) 

Parameters

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

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

browsePath
OpcLabs.EasyOpc.UA.Navigation.UABrowsePath. If successful, the browse path object corresponding to the input string.

The value of this parameter 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 an absolute OPC-UA browse path and displays its starting node and 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 TryParse
    {
        public static void Main1()
        {
            var browsePathParser = new UABrowsePathParser();

            IStringParsingError stringParsingError = browsePathParser.TryParse(
                "[ObjectsFolder]/Data/Static/UserScalar", 
                out UABrowsePath browsePath);

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

            Console.WriteLine("StartingNodeId: {0}", browsePath.StartingNodeId);

            foreach (UABrowsePathElement browsePathElement in browsePath.Elements)
                Console.WriteLine(browsePathElement);

            // Example output:
            // StartingNodeId: ObjectsFolder
            // /Data
            // /Static
            // /UserScalar
        }
    }
}
' Attempts to parses an absolute  OPC-UA browse path and displays its starting node and 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 TryParse
        Public Shared Sub Main1()
            Dim browsePathParser = New UABrowsePathParser()

            Dim browsePath As UABrowsePath = Nothing
            Dim stringParsingError As IStringParsingError = browsePathParser.TryParse("[ObjectsFolder]/Data/Static/UserScalar", browsePath)

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

            Console.WriteLine("StartingNodeId: {0}", browsePath.StartingNodeId)

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

            ' Example output:
            ' StartingNodeId: ObjectsFolder
            ' /Data
            ' /Static
            ' /UserScalar
        End Sub
    End Class
End Namespace
// Attempts to parse an absolute  OPC-UA browse path and displays its starting node and 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 TryParse.Main;
var
  BrowsePath: _UABrowsePath;
  BrowsePathElement: _UABrowsePathElement;
  BrowsePathParser: OpcLabs_EasyOpcUA_TLB._UABrowsePathParser;
  BrowsePathResult: OleVariant;
  Count: Cardinal;
  Element: OleVariant;
  ElementEnumerator: IEnumVariant;
  StringParsingError: _StringParsingError;
begin
  BrowsePathParser := CoUABrowsePathParser.Create;

  StringParsingError := BrowsePathParser.TryParse('[ObjectsFolder]/Data/Static/UserScalar', BrowsePathResult);

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

  BrowsePath := IUnknown(BrowsePathResult) as _UABrowsePath;
  WriteLn('StartingNodeId: ', BrowsePath.StartingNodeId.ToString);

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

  // Example output:
  // StartingNodeId: ObjectsFolder
  // Elements:
  // /Data
  // /Static
  // /UserScalar

end;
// Attempts to parses an absolute  OPC-UA browse path and displays its starting node and 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.

$BrowsePath = new COM("OpcLabs.EasyOpc.UA.Navigation.UABrowsePath");

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

$StringParsingError = $BrowsePathParser->TryParse("[ObjectsFolder]/Data/Static/UserScalar", $BrowsePath);

// 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 < $BrowsePath->Elements->Count; $i++)
{
    printf("%s\n", $BrowsePath->Elements[$i]);
}

// Example output:
// StartingNodeId: ObjectsFolder
// Elements:
// /Data
// /Static
// /UserScalar
REM Attempts to parses an absolute  OPC-UA browse path and displays its starting node and 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 TryParse_Main_Command_Click()
    OutputText = ""
    
    Dim BrowsePathParser As New UABrowsePathParser

    Dim stringParsingError As stringParsingError
    Dim browsePath As Variant
    Set stringParsingError = BrowsePathParser.TryParse("[ObjectsFolder]/Data/Static/UserScalar", browsePath)
    
    ' Display results
    If Not stringParsingError Is Nothing Then
        OutputText = OutputText & "*** Error: " & stringParsingError & vbCrLf
        Exit Sub
    End If
    
    OutputText = OutputText & "StartingNodeId: " & browsePath.StartingNodeId & vbCrLf
    
    OutputText = OutputText & "Elements:" & vbCrLf
    Dim BrowsePathElement: For Each BrowsePathElement In browsePath.Elements
        OutputText = OutputText & BrowsePathElement & vbCrLf
    Next

    ' Example output:
    'StartingNodeId: ObjectsFolder
    'Elements:
    '/Data
    '/Static
    '/UserScalar
End Sub
# Attempts to parse an absolute OPC-UA browse path and displays its starting node and 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 *


browsePathParser = UABrowsePathParser()

stringParsingError, browsePath = browsePathParser.TryParse('[ObjectsFolder]/Data/Static/UserScalar', None)

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

print('StartingNodeId: ', browsePath.StartingNodeId, sep='')

print()
for browsePathElement in browsePath.Elements:
    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