modifying .xml file using vb script

Discussion in 'JavaScript and AJAX' started by pt88john, Oct 3, 2011.

  1. pt88john

    pt88john New Member

    Joined:
    Oct 3, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i have written a VB script which opens a xml file and replace the whole line if it founds a sub string of it, bleow i am giving you my script.

    In the belwo script, it open the file "enduser.xml" and if any line contains the word "Check the new login value" then the whole line be replaced with a new
    line that is "<option name=""Check the new login value"" value=""1000""/>"
    ***********************************************************************
    Set Filehandle = CreateObject("Scripting.FileSystemObject")
    Set openFile = Filehandle.OpenTextFile("enduser.xml")
    aText = Split(openFile.ReadAll, VbCrLf)
    openFile.Close
    Set openFile = Filehandle.CreateTextFile("enduser.xml", True)
    For Each srcLine In aText
    If InStr(1, srcLine, "Check the new login value", 1) = 0 Then
    openFile.WriteLine srcLine
    Else
    openFile.WriteLine "<option name=""Check the new login value"" value=""1000""/>"
    End If
    Next
    openFile.Close
    ***********************************************************************
    My current Requirement:-

    Now, in the same above same script i want to add a piece to check for a line called <option name="bpel coponent">, if the line doesn't exist then it has to
    write below lines of code( below 4 bold lines) into the enduser.xml file. But trick here is it should not overwirte the file content, In the end of the file i have a line called
    </enuseroptions>, these new lines should go on top of this line.

    <category name="bpel coponent">
    <option name="check the component availability" value="1"/>
    <option name="new component is" value="bpel"/>
    </category>


    </enuseroptions> -----> This is the last line of my file, the new code (above 4 flines) should appear above this line and a gap should be there between the
    new code and this line.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    set objDoc = Server.CreateObject("Microsoft.XMLDOM")
    objDoc.load("sample.xml")
    
    For Each objNetworkNode in objNetWorkNodeLis
    	' iterate like that
    Next
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice