相关疑难解决方法(0)

使用jQuery $().find解析带有命名空间的XML

我正在尝试获取XML文档元素的内容,但该元素的名称中包含冒号.

此行适用于每个元素,但名称中带有冒号的元素:

$(this).find("geo:lat").text();
Run Code Online (Sandbox Code Playgroud)

我认为冒号需要逃脱.我该如何解决?

javascript xml jquery namespaces

21
推荐指数
2
解决办法
3万
查看次数

如何单独使用jQuery解析xml属性?

我已经成功解析了xml,但我仍然坚持获得孩子们的属性.

XML示例:

<entries>
    <entry>
        <media:thumbnail url="blah" />
    </entry>
</entries>
Run Code Online (Sandbox Code Playgroud)

Javascript/jQuery:

$.get('data.xml', function(d){
    $(d).find('entry').each(function(){
        var $entry = $(this);
        var pic = $entry.find('media:thumbnail').attr('url');
    })
});
Run Code Online (Sandbox Code Playgroud)

那个javascript对我来说不起作用.有什么问题?

javascript xml jquery

17
推荐指数
1
解决办法
4万
查看次数

使用 jQuery 解析自定义 XML 架构

我正在从 AJAX 调用返回自定义架构数据,并且需要使用 jQuery 对其进行解析。知道如何做到这一点吗?

这是 XML:

<xsd:get_customer_summary_response xmlns:xsd="http://com/acmeco/ovm/cas/xsd">
  <xsd:customer_details>
    <typ:phone_number xmlns:typ="http://com/acmeco/ovm/cas/types">1.555.5553002</typ:phone_number>
    <typ:timezone xsi:nil="true" xmlns:typ="http://com/acmeco/ovm/cas/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <typ:zipcode xmlns:typ="http://com/acmeco/ovm/cas/types">3002</typ:zipcode>
...
  </xsd:customer_details>
</xsd:get_customer_summary_response>
Run Code Online (Sandbox Code Playgroud)

这是 AJAX 调用。我可以使用下面的内容解析普通的 XML,但不能解析 XSD 的内容。

   $.ajax({
       type: "GET",
       url: "so.xml",

       dataType: "html",

        success: function(returnhtml){ 
    $("customer_details", returnhtml).find("zipcode").each(function() {
        alert($(this).text());
    });
    }, etc.
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

javascript jquery xsd

5
推荐指数
1
解决办法
8071
查看次数

jQuery XML解析如何获取元素属性

XML:

<item>
     <title>Some title</title>

     <description>
     <![CDATA[
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
     ]]>
     </description> …
Run Code Online (Sandbox Code Playgroud)

xml jquery

5
推荐指数
1
解决办法
2万
查看次数

Javascript命名空间的html元素

我正在写一些学术性的东西,我有命名空间的html元素,如:

<ns:LinkList id="sitesuteis" cssClass="classone">
            <ns:LinkItem id="LI1" href="http://www.ibt.pt/" target="_blank">IBT</ns:LinkItem>
            <ns:LinkItem id="LI2" href="http://http://html5demos.com/t/" target="_blank">HTML5 Demos</ns:LinkItem>
            <ns:LinkItem id="LI3" href="http://diveintohtml5.ep.io/" target="_blank">Dive into HTML5</ns:LinkItem>
            <ns:LinkItem id="LI4" href="http://html5boilerplate.com/" target="_blank">HTML5 Boilerplate</ns:LinkItem>
        </ns:LinkList>
Run Code Online (Sandbox Code Playgroud)

现在,在javascript我正在尝试:

    var elements = document.getElementsByTagName('ns:LinkItem');
    element = elements[0];
    console.log(element.getAttribute('id'));
    //I get a correct value in all browsers
Run Code Online (Sandbox Code Playgroud)

试图在我的元素[0]中获取所有ChildNodes.它适用于所有浏览器,但-IE lt 9-除外

我试过了:

var children = element.getElementsByTagName('ns:LinkItem');
console.log(children.length);
Run Code Online (Sandbox Code Playgroud)

和:

var children = Array();
for (i=0; i<element.childNodes.length; i++){
   alert(element.childNodes[i].nodeName);
   if (element.childNodes[i].nodeName=="NS:LINKITEM"){
      children.push(element.childNodes[i]);
   }
}
console.log(children.length);
Run Code Online (Sandbox Code Playgroud)

在两个console.logs中,除了IE8或更少,我得到每个浏览器中正确的长度(4),我得到0.

根据@Shadow向导在IE8及以下版本中,元素的canHaveChildren属性为false,这意味着死胡同 - 浏览器根本不支持为此标记
设置子节点,例如,不能有子节点的方式.我试过了,这是真的.如果我尝试:

element.parentNode  
Run Code Online (Sandbox Code Playgroud)

在IE 8或更低版本中,我得到包含我的标记的div,在其他浏览器中,我得到了我的父母

我真的需要一个黑客,我似乎找不到一个.

html javascript internet-explorer dom

5
推荐指数
1
解决办法
1888
查看次数

如何使用jQuery解析XML响应

我试图使用jQuery解析xml响应,只输出一个页面的元素,但我没有成功.

下面是我用于响应和解析它的代码.

$.ajax({
    url: UCMDBServiceUrl,
    type: "POST",
    dataType: "xml",
    data: soapMessage,
    success: UCMDBData,
    crossDomain: true,
    contentType: "text/xml; charset=\"utf-8\""
});
alert("Sent2");
return false;
}

function UCMDBData(xmlHttpRequest, status, msg)
{
     alert("Came back1");
     $(xmlHttpRequest.responseXML).find('tns:CIs').each(function()
     {
        alert("Came back2");
        $(this).find("ns0:CI").each(function()
        {
            alert("Came back3");
            $("#output").append($(this).find("ns0:ID").text());
        });
     });     
}
Run Code Online (Sandbox Code Playgroud)

我收到"Came back1"的警报但它似乎没有进一步.下面是我尝试使用上面的jquery代码解析的XML响应.我最终试图退出响应的文本在这个元素中

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header />
    <soapenv:Body>
        <tns:getFilteredCIsByTypeResponse xmlns:ns0="http://schemas.hp.com/ucmdb/1/types" xmlns:ns1="http://schemas.hp.com/ucmdb/ui/1/types" xmlns:ns2="http://schemas.hp.com/ucmdb/1/types/query" xmlns:ns3="http://schemas.hp.com/ucmdb/1/types/props" xmlns:ns4="http://schemas.hp.com/ucmdb/1/types/classmodel" xmlns:ns5="http://schemas.hp.com/ucmdb/1/types/impact" xmlns:ns6="http://schemas.hp.com/ucmdb/1/types/update" xmlns:ns7="http://schemas.hp.com/ucmdb/discovery/1/types" xmlns:ns8="http://schemas.hp.com/ucmdb/1/types/history" xmlns:tns="http://schemas.hp.com/ucmdb/1/params/query">
            <tns:CIs>
                <ns0:CI>
                    <ns0:ID>4d030502995a00afd989d3aeca2c990c</ns0:ID>
                    <ns0:type>nt</ns0:type>
                    <ns0:props>
                        <ns0:strProps>
                            <ns0:strProp>
                                <ns0:name>name</ns0:name>
                                <ns0:value>prodoo</ns0:value>
                            </ns0:strProp>
                        </ns0:strProps>
                        <ns0:booleanProps>
                            <ns0:booleanProp>
                                <ns0:name>host_iscomplete</ns0:name>
                                <ns0:value>false</ns0:value>
                            </ns0:booleanProp>
                        </ns0:booleanProps>
                    </ns0:props> …
Run Code Online (Sandbox Code Playgroud)

html javascript xml jquery

5
推荐指数
1
解决办法
6272
查看次数

使用jQuery通过命名空间查找XML节点

我们有一个XML文件,其中一些节点是命名空间的.基本上文件看起来像这样:

<foo>
    <bar xmlns:x="http://www.example.com/">
        <x:bla foo="bar" />
    </bar>
</foo>
Run Code Online (Sandbox Code Playgroud)

我们想要实现的是我们想要选择x:bla节点,但不幸的是我们事先并不知道节点的名称,只知道它的名称空间.因此我们所知道的基本上就是它是一个x:*节点.

现在,问题是:find一旦我们使用$.parseXML?解析XML文件,我们如何使用jQuery的方法选择这个节点?

使用$(xml).find("x\\:bla, bla")作品,但前提是我知道该节点被调用bla.

xml jquery namespaces find

5
推荐指数
1
解决办法
5293
查看次数

使用jquery在其中注入具有冒号的属性的标记

我正在尝试使用jquery在div中注入以下span.

HTML:
<span epub:type="pagebreak" id="pagePrefix" title="1"></span>

JS:
$('div').html('<span epub:type="pagebreak" id="pagePrefix" title="1"></span>');
Run Code Online (Sandbox Code Playgroud)

并收到以下错误, SyntaxError: DOM Exception 12

任何解决方法吗?

javascript xhtml jquery

2
推荐指数
1
解决办法
1341
查看次数

使用jQuery解析xml命名空间.需要帮助!

我是ajax的新手.我已经通过jquery完成了正常的xml解析,但无法使用命名空间工作的xml.我在网上搜索过,我找到的资源非常少.这是stackoverflow中的一篇文章,但它对我不起作用.

使用命名空间进行jQuery XML解析

这是xml文件的一部分.假设我需要xml数据中的年份编号.我怎么会得到它?

<aws:sunset>
                <aws:year number="2011" />
                <aws:month number="3" text="March" abbrv="Mar" />
                <aws:day number="27" text="Sunday" abbrv="Sun" />
                <aws:hour number="7" hour-24="19" />
                <aws:minute number="10" />
                <aws:second number="28" />
                <aws:am-pm abbrv="PM" />
                <aws:time-zone offset="-5" text="Central Daylight Time (USA)" abbrv="CDT" />
    </aws:sunset>
Run Code Online (Sandbox Code Playgroud)

等待你的回复.谢谢!

javascript xml jquery namespaces

1
推荐指数
1
解决办法
3785
查看次数

标签 统计

jquery ×8

javascript ×7

xml ×6

namespaces ×3

html ×2

dom ×1

find ×1

internet-explorer ×1

xhtml ×1

xsd ×1