JQuery Selector in XML

有些话、适合烂在心里 提交于 2019-12-25 04:03:37

问题


I am attempting to get a set of elements from an XSD document. I have downloaded and I am using the latest version of jQuery (1.7.2). The xsd referenced is a local copy of http://www.w3.org/2001/XMLSchema.xsd the code I am using is as follows:

var xml;
$(function(){
    $.ajax({
        type:"GET",
        url:"http://www.w3.org/2001/XMLSchema.xsd",//"xml/XMLSchema.xsd",
        dataType: 'xml',
        success:function(result){
            xml = $(result);
        }
    });
});

This enables me to load the xsd into the "xml" variable as expected however when I go to query it I end up with some confusing results. Using:

$('complexType[name=simpleType]', xml).attr("name")
$('complexType[name="simpleType"]', xml).attr("name")

return "undefined" however the starts with, ends with and start and ends with return the correct result:

$('complexType[name^="simpleType"]', xml).attr("name")
$('complexType[name$="simpleType"]', xml).attr("name")
$('complexType[name$="simpleType"][name^="simpleType"]', xml).attr("name")

Which is the name "simpleType". Is there a reason why the ='s does not work?

Thanks in advance


回答1:


I think that you have problem with the usage of namespace. You can try to use

$('xs\\:complexType[name=simpleType]', xml).attr("name")

(see about escaping of meta-characters here) instead of

$('complexType[name=simpleType]', xml).attr("name")


来源:https://stackoverflow.com/questions/10961874/jquery-selector-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!