2

I have a function which reads a string to an XMLDocument.

I wish to then output the XML in that document to the screen.

Dim L As String = P.ToString()
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(L)
Context.Response.Write(xmlDoc)

the above does not work, I have also tried using

Return(xmlDoc)

with no success. How should I perform this function? Should I not be using XMLDocument?

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
BTC
  • 3,802
  • 5
  • 26
  • 39

2 Answers2

0
        StringWriter stringWriter = new StringWriter();
        XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);

        document.WriteTo(xmlTextWriter);

        Console.WriteLine(stringWriter.ToString());
        Console.Read();
0

One of the possible ways is to use a StringWriter:

Using stringWriter = New StringWriter()
    Using xmlTextWriter = XmlWriter.Create(stringWriter)
        xmlDoc.WriteTo(xmlTextWriter)
        xmlTextWriter.Flush()
        result = stringWriter.GetStringBuilder().ToString()
    End Using
End Using

On the example above, your XML will be stored into the result variable.

The C# equivalent code may be found on this thread.

Community
  • 1
  • 1
OnoSendai
  • 3,960
  • 2
  • 22
  • 46