XML中的JQuery选择器 [英] JQuery Selector in XML

查看:86
本文介绍了XML中的JQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从XSD文档中获取一组元素.我已经下载并且正在使用最新版本的jQuery(1.7.2).引用的xsd是 http://www.w3.org/2001/XMLSchema.xsd的本地副本我使用的代码如下:

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);
        }
    });
});

这使我能够按预期将xsd加载到"xml"变量中,但是当我对其进行查询时,最终会得到一些令人困惑的结果.使用:

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")

返回"undefined",但是以开头,结尾,开头和结尾返回正确的结果:

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")

名称为"simpleType". =不能正常工作是有原因的吗?

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

预先感谢

推荐答案

我认为您在使用命名空间时遇到问题.您可以尝试使用

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")

这篇关于XML中的JQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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