开发者

Displaying XML with XSLT formatting in MVC

开发者 https://www.devze.com 2023-04-09 08:13 出处:网络
I\'d like my view to display a raw XML file formatted with an XSLT file inside an iframe. The XML file actually shown is variable and depends on the user\'s selection from a form (the XML file\'s addr

I'd like my view to display a raw XML file formatted with an XSLT file inside an iframe. The XML file actually shown is variable and depends on the user's selection from a form (the XML file's address is determined in the controller).

Is it possible to return the XML information directly from my controller, and if so, how? My main consideration is how to use an iframe in my view an开发者_运维知识库d have the id updated by my AJAX form. Initially, my controller action merely returned a string representing the XML file address, but I had trouble manipulating my JavaScript to accept this return value and parse it into document.getElementById.src = url.

Current code:

Dim docXML As New XmlDocument()
docXML.Load("C:\SharpSVN\" + cprotocols + "_Config.xml")

Using nodeReader = New XmlNodeReader(docXML)
    nodeReader.MoveToContent()

    Dim xRoot As XElement = XElement.Load(nodeReader)
    Return xRoot.ToString()
End Using

This is without XSLT, and the xRoot also only returns the data in one line (I'd like to see the element tags as well as correct formatting with spaces).


Use a pretty-print stylesheet or a serialize stylesheet to format the raw XML with the correct whitespace and line breaks.

References

  • Mozilla: XML Pretty Print
0

精彩评论

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

关注公众号