QuickOPC 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.
OpcLabs.EasyOpc.UA.Navigation.UABrowsePath. If successful, the browse path object corresponding to the input string.
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.
browsePath
OpcLabs.EasyOpc.UA.Navigation.UABrowsePath. If successful, the browse path object corresponding to the input string.

Return Value

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

.NET

COM

// Attempts to parse an absolute OPC-UA browse path and displays its starting node and elements.

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

namespace UADocExamples._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 parse an absolute OPC-UA browse path and displays its starting node and elements.

# 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.')
' Attempts to parses an absolute  OPC-UA browse path and displays its starting node and elements.

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 parses an absolute  OPC-UA browse path and displays its starting node and elements.

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.

$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.

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
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