0

XmlTextWriterの出力データを文字列変数にエクスポート(変換)したいと思います。

私のコードは次のとおりです:

        '' write data as xml
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("Transaction")
        objX.WriteAttributeString("version", "1.0")
        objX.WriteElementString("id", "12")
        objX.WriteElementString("token", "4534gfdgdfhfst")


        objX.WriteEndElement()

        objX.WriteEndDocument()

        objX.Flush()

        objX.Close()
        Response.End()

現在取得しているxml出力は次のようになります:38824e4760a1b72f9bd95723a3bdffbd02280010.50en3475990rapids1 month rapidshare0.46587748175.136.184.1539/14/2012d7a1ff2200f9fe7b8b89d12fdc8be8f36293‌​712eS. how to make it as xml tags

4

1 に答える 1

5

XmlTextWriterに直接書き込むようにを設定しましたResponse.OutputStream。文字列変数にエクスポートする場合は、StringWriterに書き込むを使用できますStringBuilder

Dim sb As New StringBuilder()
Using sw As New StringWriter(sb)
    Using writer = XmlWriter.Create(sw)
        ' write the XML to the writer here
    End Using
End Using
' At this stage the StringBuilder will contain the generated XML.

別の方法として、次のように書くことができますMemoryStream

Using stream As New MemoryStream()
    Using writer = XmlWriter.Create(stream)
        ' write the XML to the writer here

        Dim xml As String = Encoding.UTF8.GetString(stream.ToArray())
        ' TODO: do something with the generated XML
    End Using
End Using
于 2012-09-23T15:21:47.860 に答える