XML Automation

navinbnavinb Member Posts: 51
Hi ,

I am trying to export records in xml format with automation but it is breaking on below code :


XMLRoot := XMLDoc.documentElement;
XMLNode := XMLRoot.ownerDocument.createNode('element', 'TableRecord', '');
XMLRoot.appendChild(XMLNode);

System is throwing an error that automation variable is not instantiated .Please suggest what i am missing here

Thanks in advance !!

Comments

  • deepaknavdeepaknav Member Posts: 18
    Please check if you have created all the automation variables you are using.
  • navinbnavinb Member Posts: 51
    Following variables are declared :

    Name DataType Subtype Length
    XMLDoc Automation 'Microsoft XML, v3.0'.DOMDocument
    XMLRoot Automation 'Microsoft XML, v3.0'.IXMLDOMNode
    XMLNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode

    And XMLDoc is created.
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Have you tried the simple solution just to write XMLDoc.createNode(...);?
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • navinbnavinb Member Posts: 51
    Yes even that throws the same error :"automation error is not intialised"
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Have you studied the patterne elsewhere in the application, e.g. REPORT 505 where an xml document is built up from scratch?
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • Tommy_SchouTommy_Schou Member Posts: 117
    Not quite sure what you are doing but in case it is any help here is a very simple way to create a 2 tag XML document using automation:
    IF ISCLEAR(XMLDoc) THEN
      CREATE(XMLDoc);
    
    NewNode := XMLDoc.createNode(1,'DocumentElementNode','NameSpaceURI');
    XMLDoc.appendChild(NewNode);
    
    CurrNode := NewNode;
    
    NewNode := XMLDoc.createNode(1,'TableRecord','NameSpaceURI');
    NewNode.text := 'TestData';
    
    CurrNode.appendChild(NewNode);
    
    XMLDoc.save('c:\tmp\test.xml');
    

    Be advised that the error: "Automation has not been instantiated" or something to that effect can also arise when you try to select a tag in an XML document if that tag is not present. Not a very descriptive error to give but if Ie. you try to select a non-existent tag name <ThisTagIsNotInTheXML> then you will not be told that the tag does not exist. Instead you will get an Automation error if you try to use the Node without first checking with ISEMPTY if a node was actually returned.
    Best regards
    Tommy
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.