使用ASHX动态XML文件
我尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.aspxSo 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 anXmlDocument
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 setDocumentSource
to a URL - not that you're providing a valid URL anyway!)问题是,我正在尝试构建 XML 的用户查看端,而另一位开发人员则构建了一个文件系统,用于将 XML 文件从单独的目录中推送和拉出。他设置了一个 ashx 文件来预览 XML;然而,这使我的工作变得复杂并导致我在这里提出我的问题。
为了解决这个问题,我只是绕过了 ashx 文件并使用它保存的代码将 xml 拉到字符串并将其绑定到 Xml webcontrol。
再次感谢您的帮助。
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.
Thanks again for your help.