在JSF中显示XML [英] Displaying XML in JSF
问题描述
我有一个方法可以返回格式化的XML字符串.我想以一种包装精美,易读的方式在JSF页面上显示这一点.我首先使用了此解决方案.
I have a method that gives back a formatted XML string. I want to show that on a JSF page in a nicely wrapped, readable way. I used this solution first.
<pre><h:outputText value="myBean.xml"/></pre>
结果是缩进的,但不会包裹很长的行(例如具有很多属性)
The result is indented, but it doesn't wrap very long lines (with a lot of attributes for e.g.)
RichFaces也可以在我的项目中使用.您会提出什么建议?
RichFaces is also available in my project. What would you suggest?
预先感谢, 丹尼尔
推荐答案
不确定我是否理解正确,但是如果它是带有XML数据的普通香草字符串,并且希望按原样显示在JSF页面中,则逻辑上的第一步是转义HTML实体,以便不将其解析为HTML.您可以为此使用h:outputText,默认情况下,它会转义HTML实体(通过"escape"属性可控制):
Not sure if I understand you right, but if it is a plain vanilla String with XML data which you want to display as-is in the JSF page, then the first logical step would be to escape the HTML entities so that it's not been parsed as HTML. You can use h:outputText for this, it by default escapes HTML entities (which is controllable by the 'escape' attribute by the way):
<h:outputText value="#{bean.xmlString}" />
或者如果已格式化并且想要保留格式,请在父HTML元素上应用CSS white-space:pre属性.
Or if it is formatted and you want to preserve the formatting, then apply the CSS white-space:pre property on the parent HTML element.
或者,如果您要添加语法突出显示(颜色等),请考虑一个执行此任务的Javascript库.谷歌搜索"javascript xml语法突出显示"应该会产生足够的结果.
Or if you want to add syntax highlighting (colors and so on), then consider a Javascript library which does the task. Googling "javascript xml syntax highlighting" should yield enough results.
这篇关于在JSF中显示XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!