-1

I need to add root element to response result xml. We are receiving xml result from another(2nd) application which is not having proper root element hence our(1st) application unable read "RETURN_CODE" whether it is success or not.

Response from 2nd application:

Set objRemoteServerPost = server.CreateObject("SOFT.ASPtear")

'AppendToLog("Before 2nd app call")
Response.ContentType = "text/html"
On Error Resume Next

'call 2nd Application to create workitem via get method

sCallResult = objRemoteServerPost.Retrieve(sUrl,Request_GET,"", "", "")
                            
Set objRemoteServerPost = nothing

Result XML from 2nd app : I have mentioned in the comment

Now I need to load this this result into xml but i am unable because result is not containing root element. Error while loading xml "Only one top level element is allowed in an XML document"

'create xml object to retrieve return code  

set xmlResult= Server.CreateObject("Microsoft.XMLDOM")

'load result into xml
xmlResult.loadXML sCallResult

' retrieve return code
set elemReturnStatus=xmlResult.selectSingleNode("//RETURN_CODE")

if not (elemReturnStatus is nothing) then

' check if call was successful

I need help to load the response result(sResult) into Load xml (xmlResult). I save the xml results but nothing inside xml.

user692942
  • 16,398
  • 7
  • 76
  • 175
Shivam
  • 17
  • 2

2 Answers2

0

Could you use the vbs replace function, eg

sCallResult = replace(sCallResult, "<response>", "<root><response>")
sCallResult = replace(sCallResult, "</RETURN_CODE>", "</RETURN_CODE></root>")

A couple of other points. First, why are you using Response.ContentType = "text/html" rather than text/xml? Second, it's almost never a good idea to use On Error Resume Next.

user692942
  • 16,398
  • 7
  • 76
  • 175
John
  • 4,658
  • 2
  • 14
  • 23
  • 2
    If a question isn't clear enough to answer without asking more questions maybe you shouldn't be answering it. If you have questions, ask for clarity in the comments. If you need to ask questions because the question is not clear or requires more details, flag it as such. – user692942 Sep 04 '22 at 22:00
-2

Using XML Linq

using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApp2
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string ident = "<?xml version = \"1.0\" ?><response>Successful</response>";
            XDocument doc = XDocument.Parse(ident);
            XElement response  = doc.Root;

            XElement returnCode = new XElement("RETURN_CODE", 0);
            response.Add(returnCode);

        }

    }

}
 
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • I have to use classic asp or vbscript to update XML – Shivam Sep 03 '22 at 17:36
  • XML Linq is a Net Product which a new version of the legacy XML library in Net. – jdweng Sep 03 '22 at 20:52
  • 1
    Classic ASP is not ASP.Net, it predates .Net. – user692942 Sep 04 '22 at 19:11
  • @user692942 : Are you saying the code is using versions of Net prior to the release of Net 3.5 in 2007? Does OP mean using VBA or equivalent? – jdweng Sep 05 '22 at 05:45
  • No, I’m saying it’s not using .Net at all. Classic ASP is a server-side processor that utilises scripting languages like VBScript and JScript. Hence the question tags. – user692942 Sep 05 '22 at 09:37
  • @jdweng Classic ASP is what there was before any version of .Net "Active Server Pages is Microsoft's first server-side scripting language and engine for dynamic web pages. It was first released in December 1996, before being superseded in January 2002 by ASP.NET." – Dijkgraaf Sep 08 '22 at 20:40