开发者

XMLTextWriter to XMLDocument

I've got an XMLTextWriter writing to a Stream of a WebRequest. Everything works as it should:

    Dim wr As WebRequest = WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/ShipAccept")
    With wr
        .Method = "POST"
        .ContentType = "application/x-www-form-urlencoded"
    End With
    Dim requestStream As Stream = wr.GetRequestStream
    Using requestStream

        Dim x As New XmlTextWriter(requestStream, Encoding.UTF8)

        Using x
            With x

                .WriteStartDocument()
                'XML

                .WriteStartElement("ShipmentAcceptRequest")
                'ShipmentAcceptRequest

                .WriteStartElement("Request")
                'Request

                .WriteElementString("RequestAction", sar.Request.RequestAction)

                '/Request
                .WriteEndElement()

                .WriteElementString("ShipmentDigest", sar.Shipmen开发者_运维技巧tDigest)

                '/ShipmentAcceptRequest
                .WriteEndElement()

                '/XML
                .WriteEndDocument()

                .Flush()

            End With
        End Using

    End Using

How can I intercept this XML that's being written as an XMLDocument type? I tried snagging it from the stream but that gave me a 'The stream does not support reading.' exception (which didn't surprise me).

Thanks


I don't think you can intercept the stream, because by it's definition it is:

a writer that provides a fast, non-cached, forward-only way of generating streams

non-cached and forward-only being your problems there.

So... anything stopping you from doing it in reverse order?

Write your XML to an XmlDocument, and when you're finished call XmlDocument.WriteTo to output the XML to an XmlWriter (in this case your XmlTextWriter outputting to your request stream).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜