将 xml 字符串显示为格式化的 xml
我有一个从服务器传递到客户端的 xml 字符串,我需要在对话框中显示该 xml。我来自服务器的 xml 响应(实际上是一个字符串)看起来像这样 -
<docbody><name>somename</name><adr><state>NY</state><zip>1111</zip><street></street></adr></docbody>
我在对话框中有一个文本区域,并且我正在使用 setText 方法来显示 xml 响应。现在的问题是,xml 显示为纯文本,我的要求是,我想以与在浏览器中打开 xml 文件时完全相同的方式显示 xml...我的意思是使用所有正确的缩进和新行对于每个标签。
在 GWT 客户端有什么办法可以做到这一点吗?我已经检查了 XMLParser,但它不能做到这一点。
I have a xml string which is passed from the server to client side and I need to show the xml in a dialog box. My xml response (which is actually a String) from the server looks something like this -
<docbody><name>somename</name><adr><state>NY</state><zip>1111</zip><street></street></adr></docbody>
I have a text area in the dialog box and i am using setText method to display the xml response. now the problem is, the xml is shown as plain text and my requirement is that, I want to display the xml exactly same way as it looks if we open a xml file in browser...I mean with all proper indentation and new lines for each tag.
Is ther any way to do this, on the client side of GWT. I have checked XMLParser, but it cannot do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要求提供纯文本字符串(恰好是 XML)来完成浏览器对 XML 文档执行的所有格式设置。
首先,这是依赖于浏览器的行为,GWT 正在从您那里抽象出一些行为,其次,文本区域不支持这种格式。
您必须将其放入 iframe 或其他内容中,并适当地设置内容的所有元信息。
You're asking for the text only string, that happens to be XML, to go through all the formatting that your browser does to XML documents.
First of all, this is browser dependent behavior, something that GWT is abstracting away from you, secondly, text areas don't support this kind of formatting.
You'd have to put it in an iframe or something and set all the meta information for the content appropriately.