Options

Reading a XML File, what am I doing wrong?

nuno.silvanuno.silva Member Posts: 29
edited 2017-07-21 in NAV Three Tier
Hi,
I need to call a web service and read the XML.
I can call the web service, receive the reply but when I try to read the values, for example put the values on a message, I always get the error “A DotNet variable has not been instantiated. Attempting to call System.Xml.XmlNode.Value in CodeUnit CallWS: GetUsers”



Any sugestion?
thanks in advance,
NS
===============
Nuno Silva

Best Answers

Answers

  • Options
    HannesHolstHannesHolst Member Posts: 119
    At which line does the debugger stop?
  • Options
    nuno.silvanuno.silva Member Posts: 29
    at the message line
    ===============
    Nuno Silva
  • Options
    HannesHolstHannesHolst Member Posts: 119
    Maybe this works?
    XMLNodeList := XMLResponseDoc.GetElementsByTagName('Utilizador');
    FOR I := 0 TO XMLNodeList.Count - 1 DO BEGIN
    XMLNodeContainer := XMLNodeList.Item(I);
    XMLNodeID := XMLNodeContainer.SelectSingleNode('Id/text()');
    XMLNodeUserName := XMLNodeContainer.SelectSingleNode('Username/text()');
    XMLNodeFullName := XMLNodeContainer.SelectSingleNode('FullName/text()');
    
    MESSAGE('%1 - %2 - %3', FORMAT(XMLNodeID.Value), FORMAT(XMLNodeUserName.Value), FORMAT(XMLNodeFullName.Value));
    END;
    
  • Options
    nuno.silvanuno.silva Member Posts: 29
    edited 2017-04-05
    The XMLNodeContainer is the type of System.Xml.XmlNode, correct?
    I get the same error.
    If I put the code below, ir runs through the records returned by the web service

    IF NOT ISNULL(XMLNodeID) THEN
    MESSAGE('%1 - %2 - %3', FORMAT(XMLNodeID.Value), FORMAT(XMLNodeUserName.Value), FORMAT(XMLNodeFullName.Value));
    ===============
    Nuno Silva
  • Options
    nuno.silvanuno.silva Member Posts: 29
    I already founded a solution below, but I think yours is best, so I replaced my solution by yours.

    Thanks @ftornero
      XMLNodeListRead := XMLResponseDoc.GetElementsByTagName('Id');
      XMLNodeID := XMLNodeListRead.Item(I);
      
      XMLNodeListRead := XMLResponseDoc.GetElementsByTagName('Username');
      XMLNodeUserName := XMLNodeListRead.Item(I);
      
      XMLNodeListRead := XMLResponseDoc.GetElementsByTagName('FullName');
      XMLNodeFullName := XMLNodeListRead.Item(I);
    

    ===============
    Nuno Silva
Sign In or Register to comment.