正如问题所述,我尝试将XmlWriter
与定义为与共享文档站点关联的http地址的目标一起使用。如何使用XmlWriter
或不使用XmlWriter
?
Dim resolver As XmlUrlResolver = New XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials
Dim doc As New XmlDocument
doc.XmlResolver = resolver
Dim feedWriter As XmlWriter = XmlWriter.Create("URL")
Select Case format
Case FeedFormats.Atom
Response.ContentType = "application/rss+xml"
Dim atomFormatter As New Atom10FeedFormatter(feed)
atomFormatter.WriteTo(feedWriter)
Case FeedFormats.Rss
Response.ContentType = "application/atom+xml"
Dim rssFormatter As New Rss20FeedFormatter(feed)
rssFormatter.WriteTo(feedWriter)
End Select
doc.Save(feedWriter)
feedWriter.Close()
这是一个片段,我没有添加我的案例或提要声明,但这是不必要的。我想这应该用输出流完成,但我不知道如何做到这一点。
答案 0 :(得分:1)
以下是完全未经测试的:
Public Sub WriteXmlToUrl(url As Uri)
Dim request AS HttpWebRequest = CTYPE(WebRequest.Create(url), HttpWebRequest)
request.Method = "POST"
request.ContentType = "application/xml"
Using stream = request.GetRequestStream
Using writer = XmlWriter.Create(stream)
rem Write your Xml
End Using
End Using
End Sub