web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

How to check if an XMLNode is Null

(0) ShareShare
ReportReport
Posted on by 525

Hi Guys
I'm working with some XML Files and need to parse it using code. the 'ISNULL' function is not available. Is there any alternative for checking if an XMLNode type variable is null? 



Categories:
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    There is an ISNULL function, but you need to code it like so:

    [boolean] := ISNULL(XMLNode)

    forum.mibuso.com/.../dotnet-variable-has-not-been-instantiated-node-is-null

  • Mohsin Abbas Profile Picture
    525 on at

    I've tried it but it says, "error AL0118: The name 'ISNULL' does not exist in the current context"

  • Verified answer
    Community Member Profile Picture
    on at

    Then as a workaround, I'm assuming that the Writeto function (docs.microsoft.com/.../xmlnode-writeto-text-method) will either return false or the text will be empty.

    Alternatively, if you know that the node is an element then you can use docs.microsoft.com/.../xmlnode-asxmlelement-method and docs.microsoft.com/.../xmlelement-isempty-property. Similarly, there are functions to check the values and count of xml classes here docs.microsoft.com/.../devenv-restapi-overview.

  • Verified answer
    Mohsin Abbas Profile Picture
    525 on at

    You're right.

    I used XMlNode.AsXMLElement.IsEmpty

  • JSebastian Profile Picture
    on at

    Can we reopen this

    Using 
    W1 13.0 (25789)

    When I use "XMlNode.AsXMLElement.IsEmpty" on an Empty variable, the function fails.

    Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavXmlNode to Microsoft.Dynamics.Nav.Runtime.NavXmlElement

    Would be nice to have stuff like this in AL language like before with ISCLEAR...



    Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLDialogException: Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavXmlNode to Microsoft.Dynamics.Nav.Runtime.NavXmlElement.
    ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLDialogException: Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavXmlNode to Microsoft.Dynamics.Nav.Runtime.NavXmlElement.
    at Microsoft.Dynamics.Nav.Runtime.NavDialog.ALError(Guid automationId, String message)
    at Microsoft.Dynamics.Nav.BusinessApplication.Report6181271.ProcessDocumentQueue_Scope_1591060101.OnRun()
    at Filter.InvokeWithFilter(NavMethodScope )
    at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
    at Microsoft.Dynamics.Nav.BusinessApplication.Report6181271.ProcessDocumentQueue(INavRecordHandle mobDocQueue)
    at Microsoft.Dynamics.Nav.BusinessApplication.Report6181271.OnInvoke(Int32 memberId, Object[] args)
    at Microsoft.Dynamics.Nav.BusinessApplication.Codeunit6181276.ProcessDocumentManual_Scope_1696599670.OnRun()
    at Filter.InvokeWithFilter(NavMethodScope )
    at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
    at Microsoft.Dynamics.Nav.BusinessApplication.Codeunit6181276.ProcessDocumentManual(INavRecordHandle mobDocQueue)
    at Microsoft.Dynamics.Nav.BusinessApplication.Codeunit6181276.OnInvoke(Int32 memberId, Object[] args)
    at Microsoft.Dynamics.Nav.BusinessApplication.Record6181279.ProcessDocument_Scope__527715333.OnRun()
    at Filter.InvokeWithFilter(NavMethodScope )
    at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
    at Microsoft.Dynamics.Nav.BusinessApplication.Record6181279.ProcessDocument(INavRecordHandle mobDocQueue)
    at Microsoft.Dynamics.Nav.BusinessApplication.Record6181279.OnInvoke(Int32 memberId, Object[] args)
    at Microsoft.Dynamics.Nav.BusinessApplication.Page6181279.Process_a45_OnAction_Scope.OnRun()
    at Filter.InvokeWithFilter(NavMethodScope )
    at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
    at Microsoft.Dynamics.Nav.BusinessApplication.Page6181279.Process_a45_OnAction()
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.InvokeMethod(ITreeObject obj, String methodName, Object[] args, Boolean resolveHandler, Boolean throwOnNotFound)
    --- End of inner exception stack trace ---
    at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.InvokeMethod(ITreeObject obj, String methodName, Object[] args, Boolean resolveHandler, Boolean throwOnNotFound)
    at Microsoft.Dynamics.Nav.Runtime.NavForm.RaiseOnAction(Nullable`1 actionId, String actionTriggerMethodName)
    at Microsoft.Dynamics.Nav.Service.NSField.ActionField(NavSession con)
    at Microsoft.Dynamics.Nav.Service.NSField.Action(NavSession session)
    at SyncInvokeActionField(Object , Object[] , Object[] )
    at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.RunInTransactionCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass24_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TransientErrorRetryCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass24_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)

  • Suggested answer
    JSebastian Profile Picture
    on at

    To avoid the error above, make it conditional. like so:

    procedure NodeIsNull(var _XMLNode: XmlNode): Boolean;

     begin

         if _XMLNode.IsXmlElement() then

             exit(_XMLNode.AsXmlElement().IsEmpty());

         exit(true);

     end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans