从XML的JavaScript / jQuery的获取HTML [英] Getting HTML from XML with JavaScript/jQuery

查看:136
本文介绍了从XML的JavaScript / jQuery的获取HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含有良好的HTML内容的标签的XML文档。我需要获得HTML到使用JavaScript我的网页。然而,由于CMS的问题,在HTML不能以&lt逃脱; ![CDATA []]>或其他任何东西,和<>必须是present,不设连接codeD到&放大器; LT; &放大器; GT;

I've got an XML document that contains a tag that has well-formed HTML content. I need to get that HTML into my page using JavaScript. However, due to CMS issues, the HTML CANNOT be escaped with < ![CDATA[ ]]> or anything else, and the <> must be present, not encoded to &lt ; &gt ;

<submenu>
    <content>
        <div>
            <h3>Hello World</h3>
            <p>Lorem <a href="ipsum.html">ipsum</a></p>
        </div>
    </content>
</submenu>

我用jQuery来获取XML并将子菜单的到一个数组。我能够得到的文本:

I've used jQuery to get the XML and put the submenu's into an array. I'm able to get the text with:

$(menuArray[n]).find('content').text();

不过,这只是返回的Hello World Lorem存有。我需要的HTML。不幸的是jQuerys的.html()方法不使用XML。

However, this just returns "Hello World Lorem ipsum". I need the HTML. Unfortunately jQuerys' .html() method doesn't work with XML.

有没有其他办法?先谢谢了。

Is there any other way? Thanks in advance.

推荐答案

不是过分的洁净的,但你能不能使用的东西就像这个例子的 jQuery对象,以SRING ,然后像做...   VAR MYHTML = $('&LT; D​​IV&GT;)。追加($(menu​​Array [n])的发现(内容)的clone()。)删除()HTML();

Not overly clean but could you not use something like found in this example JQuery Object to Sring and do something like... var myHTML = $('<div>').append($(menuArray[n]).find('content').clone()).remove().html();

丑陋,但我知道的应该的工作

Ugly I know but should work

这篇关于从XML的JavaScript / jQuery的获取HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆