Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery解析xml文件而不丢失html标记,如_Jquery_Html_Xml - Fatal编程技术网

如何使用jquery解析xml文件而不丢失html标记,如

如何使用jquery解析xml文件而不丢失html标记,如,jquery,html,xml,Jquery,Html,Xml,,? 我有一个xml文件,我正在尝试使用jquery解析它。通过jquery读取时,我得到的输出是单个字符串,而不是所需的格式 我有一个xml文件,比如 <p>The <b> <i>maximum</i> </b>allowable incentive.</p>

? 我有一个xml文件,我正在尝试使用jquery解析它。通过jquery读取时,我得到的输出是单个字符串,而不是所需的格式

我有一个xml文件,比如

                <p>The

                    <b>

                        <i>maximum</i>

                    </b>allowable incentive.</p>

                <p>

                    <b>Medicare Incentives</b>

                </p>

                <p>For Medicare, to receive</p>

                <p>

                    <b>Medicare Disincentives</b>

                </p>

                <p>Beginning in 2015, Medicare EPs </p>

我不确定您是否正在尝试将DOM对象恢复到XML对象的内部,但如果您正在尝试,您可能希望查看Javascript DOM解析器

$(document).ready(function() {

    $.ajax({
        type: "GET",
        url: "http://localhost:8080/XMLRead/chapter01.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('page').each(function() {
                var id = $(this).attr('li');
                console.log('id ' + id);
                if (id == '1.3.1.1') {
                    var data = $(this).find('content-text').text();
                    console.log('data ' + data);
                    $(this).find('content-text').clone().appendTo('#left-container');

                }
            });
        }
    });
});​
if (window.DOMParser)
  {
      parser=new DOMParser();
      xmlDoc=parser.parseFromString(text,"text/xml");
  }
else // Internet Explorer
  {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.loadXML(text);
  }