使用ASHX动态XML文件

发布于 2024-10-28 21:13:54 字数 400 浏览 6 评论 0原文

我尝试使用 XML Web 控件提取 XML 文件的文件路径时遇到问题。 XML 文件存储在不同的目录中,我使用 ashx 文件来提供它。 ashx 文件的工作原理是将 XML 文件名附加到字符串末尾。

Dim oXML As New System.Web.UI.WebControls.Xml
oXML.DocumentSource = Server.MapPath("xmlHandler.ashx") & "?xml=sampleXMLfile.xml"
oXML.TransformSource = Server.MapPath("xmlStyles.xslt")
oXML.DataBind()

这似乎对我不起作用,我想知道将 XML 拉入后面的代码是否是唯一的方法?

感谢您的帮助!

I'm having an issue where I try to pull the filePath of an XML file using the XML web control. The XML file is stored in a different directory and I am using an ashx file to serve it up. The ashx file works by appending the XML file name to the end of the string.

Dim oXML As New System.Web.UI.WebControls.Xml
oXML.DocumentSource = Server.MapPath("xmlHandler.ashx") & "?xml=sampleXMLfile.xml"
oXML.TransformSource = Server.MapPath("xmlStyles.xslt")
oXML.DataBind()

This doesn't seem to be working for me, and I was wondering if pulling the XML into the code behind is the only way?

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-11-04 21:13:54

MapPath 将 HTTP 路径/虚拟路径映射到物理文件夹:http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

结果是,c:\file\on\ disk\etc\xmlHandler.ashx?xml=sampleXMLfile.xml,没有意义:它不是本地文件名。

如果您想下载该 URL,请查看 WebClient 类:http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx

。 ..然后将 DocumentSource 设置为从生成的下载数据、字符串或本地文件路径加载的 XmlDocument,按照 http://msdn.microsoft.com/en -us/library/system.web.ui.webcontrols.xml.documentsource(v=vs.80).aspx (如您所见,您无法将 DocumentSource 设置为URL - 并不是说​​您提供了有效的 URL!)

MapPath maps a HTTP path/virtual path to a physical folder: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

So the result, c:\file\on\disk\etc\xmlHandler.ashx?xml=sampleXMLfile.xml, doesn't make sense: it's not a local filename.

If you want to download that URL, take a look at the WebClient class: http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx

...then set DocumentSource to an XmlDocument loaded from the resulting downloaded data, or a string, or a local file path, as per http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xml.documentsource(v=vs.80).aspx (As you can see, you can't set DocumentSource to a URL - not that you're providing a valid URL anyway!)

狂之美人 2024-11-04 21:13:54

问题是,我正在尝试构建 XML 的用户查看端,而另一位开发人员则构建了一个文件系统,用于将 XML 文件从单独的目录中推送和拉出。他设置了一个 ashx 文件来预览 XML;然而,这使我的工作变得复杂并导致我在这里提出我的问题。

为了解决这个问题,我只是绕过了 ashx 文件并使用它保存的代码将 xml 拉到字符串并将其绑定到 Xml webcontrol。

Dim fRead = New IO.FileStream(filePath, IO.FileMode.Open)
Dim sReader = New IO.StreamReader(fRead)
xmlString = sReader.ReadToEnd()
fRead.Close()
sReader.Close()

Dim oXML As New System.Web.UI.WebControls.Xml
oXML.DocumentContent = xmlString 
oXML.TransformSource = Server.MapPath("getTSP.xslt")
oXML.DataBind()
Panel1.Controls.Add(oXML)

再次感谢您的帮助。

The issue was that I was trying to build the user viewing side of the XML while a fellow developer built a file system for pushing and pulling the XML files out of a separate directory. He had setup an ashx file to preview the XML; however this complicated my work and led me to ask my question here.

To solve the problem I just bypassed the ashx file and used the code it held to pull the xml to string and bind it to the Xml webcontrol.

Dim fRead = New IO.FileStream(filePath, IO.FileMode.Open)
Dim sReader = New IO.StreamReader(fRead)
xmlString = sReader.ReadToEnd()
fRead.Close()
sReader.Close()

Dim oXML As New System.Web.UI.WebControls.Xml
oXML.DocumentContent = xmlString 
oXML.TransformSource = Server.MapPath("getTSP.xslt")
oXML.DataBind()
Panel1.Controls.Add(oXML)

Thanks again for your help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文