Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting Value in XML
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi

I am trying to insert multiple line in the XML using for loop. When I execute I am getting syntax error after Next stmt.

Code:
Input_request = "<soapenv:Envelope xmlns:soapenv="&chr(34)&">"_
   &"<soapenv:Header/>"_
   &"<soapenv:Body>"_
      &"<rm:itemSouring>"_
         &"<rm:itemNames>"
        For each x in rackNm
    Writeline "<rm:item>"&x&"</rm:item>"
            Next
            &"</rm:itemNames>"_
          &"</rm:itemSouring>"_
     &"</soapenv:Body>"_
&"</soapenv:Envelope>"


Can anyone tell me what is wrong.
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
A couple of things are wrong here. First, Writeline is a function of the Scripting.FileSystemObject so you can't just call that function without its associated object. To concatenate strings to a variable in VBScript, you simply have to say var = var & "more string". Also, to get quotes in VBScript you simply have to type two together. If you are trying to get soapenv="" in your output, you have to double the quotes in the string constant "soapenv="""">". Seems silly, but that's how it works.

Code:
Dim rackNm, Input_request

rackNm = Array(1, 2, 3, 4, 5)

Input_request = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soapenv:Header />" & _
"<soapenv:Body>" & _
"<rm:itemSouring>" & _
"<rm:itemNames>"

For Each x In rackNm
Input_request = Input_request & "<rm:item>" & x & "</rm:item>"
Next

Input_request = Input_request & "</rm:itemNames>" & _
"</rm:itemSouring>" & _
"</soapenv:Body>" & _
"</soapenv:Envelope>"

MsgBox Input_request

If you are wanting to add the new line character to make the formatting look decent, then you might try something like this:

Code:
Dim rackNm, Input_request

rackNm = Array(1, 2, 3, 4, 5)

Input_request = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbNewLine & _
vbTab & "<soapenv:Header />" & vbNewLine & _
vbTab & "<soapenv:Body>" & vbNewLine & _
vbTab & vbTab & "<rm:itemSouring>" & vbNewLine & _
vbTab & vbTab & vbTab & "<rm:itemNames>" & vbNewLine

For Each x In rackNm
Input_request = Input_request & vbTab & vbTab & vbTab & vbTab & "<rm:item>" & x & "</rm:item>" & vbNewLine
Next

Input_request = Input_request & vbTab & vbTab & vbTab & "</rm:itemNames>" & vbNewLine & _
vbTab & vbTab & "</rm:itemSouring>" & vbNewLine & _
vbTab & "</soapenv:Body>" & vbNewLine & _
"</soapenv:Envelope>"

MsgBox Input_request

Kind of messy, but it does the job.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inserting variable values into Descriptive Programming Functions eske99 2 3,139 12-18-2015, 01:47 PM
Last Post: vinod123
  Getting an 'Error in XML document' Error when submitting web services XML luckyexpert 0 2,929 08-20-2013, 10:23 PM
Last Post: luckyexpert
  Inserting Images in the Word file. atulparate 2 6,416 04-09-2012, 12:44 PM
Last Post: swathi
  Need URGENT help how to read xml string / xml tag value in web page using QTP VQTP 2 5,700 04-16-2009, 02:27 AM
Last Post: VQTP

Forum Jump:


Users browsing this thread: 1 Guest(s)