SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Feb 2008
    Location
    Los Angeles, CA, USA
    Posts
    861
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Unable to save changes to XML file thru a fn call

    Hi all

    I am writing a smoke test wherein a function (e.g. sWebEdit())recognizes all the elements on a particular webpage of same class (e.g. webEdit) and another function xmlAddWebEdit() writes all those (WebEdit)objects to an XML result file. The problem is once the control is back to the script from the xmlAddWebEdit() function, the changes made to the XML file are not saved.

    'this line calls the function sWebEdit which returns an array of objects of class WebEdit
    t2Array = sWebEdit(GlobalDictionary("PageElement")(i))

    'this statement calls a function that creates child nodes in the XML result file - creating one child for each object
    Call xmlAddWebEdit(t2Array(x), currentPIndex, x, i+1)

    This file contains the statements
    xmlDoc.LoadFile(at the start of the function) & xmlDoc.SaveFile(at the end of the function)

    These functions and the entire script works fine if I define the functions within the script. But if I define these functions in an external .vbs file, the changes made to the XML are lost.

    Any idea how can I avoid this?

    -Suchit
    -Suchit

  2. #2
    Member
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    35
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Unable to save changes to XML file thru a fn call

    I would say that possibly your xmlDoc object isn't being defined correctly, as such when you run externally it is missing the required references compared to running as a script. Paste your function so I can have a look.
    Eleonora Faraone
    Melbourne VIC Australia

    eleonorafaraone@yahoo.com.au

  3. #3
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Unable to save changes to XML file thru a fn c

    Such problem would occur if you define the variable in Action and try and use it in VBS file.

  4. #4
    Senior Member
    Join Date
    Feb 2008
    Location
    Los Angeles, CA, USA
    Posts
    861
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Unable to save changes to XML file thru a fn c

    Thanks Tarun, eleonoraf for your response

    1. I have verified the definition of xmlDoc object. If I copy the same function definition into the script, it works.

    2. .vbs file has its own variables.

    I am attaching the .vbs file
    Attached Files Attached Files
    -Suchit

  5. #5
    Senior Member
    Join Date
    Feb 2008
    Location
    Los Angeles, CA, USA
    Posts
    861
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Unable to save changes to XML file thru a fn c

    Found the error / solution

    '####(A)###
    '-------Script---------
    ...
    ...
    Set xmlDoc = xmlUtil.CreateXML
    xmlDoc.LoadFile xmlFilePath
    ...
    Call Function(a,b,c)
    ...
    '(1)
    xmlDoc.SaveFile xmlFilePath
    '----End Script-----------

    '###(B)###
    '----Function in .vbs file -------
    Function (a,b,c)
    ...
    Set xmlDoc = xmlUtil.CreateXML
    xmlDoc.LoadFile xmlFilePath
    ...
    ...
    '(2)
    xmlDoc.SaveFile xmlFilePath

    End Function
    '----------.vbs file over ---------

    '###(C)###

    At the end of function call, the changes in xmlDoc object are saved in xml file xmlFilePath (2)

    Once the control is back to the script and when the script executes the statement xmlDoc.SaveFile (1), the current content of xmlDoc are saved in xml file xmlPath

    '---------------
    '###(D)###

    When the function definition is within the script, xmlDoc variable is global and accessible to all functions within the script. But when these function definitions are transferred to a .vbs (external) file, then there are 2 instances of variable xmlDoc - one in the script and one local to the function file.

    Now the changes made to xmlDoc within the function affects the local xmlDoc variable and not the one in the script.

    Hence the statement xmlDoc.SaveFile (1) in the script at the end of the script overwrites the xml file xmlFilePath with the state of the xml file before function calls
    '-----------------
    '###(E)###

    I now pass the reference to xmlDoc object in the function call

    Hence
    Call Function (a,b,c) now is Call Function(xmlDoc, a, b, c)

    Note: Make sure to use the same variable name in the script and the function i.e. xmlDoc everywhere.

    -Suchit
    -Suchit

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.11%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:47 PM.

Copyright BetaSoft Inc.