Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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解析这里的问题是什么?_Jquery - Fatal编程技术网

jQuery Xml解析这里的问题是什么?

jQuery Xml解析这里的问题是什么?,jquery,Jquery,我有这个代码,我想遍历所有com.abc.db.ConfigInfo行,如果其中任何一行包含cfgIdas141alert(cfgName) 已更新 alert(xml); $(xml).find('list com\\.abc\\.db\\.ConfigInfo').each(function() { alert("enter the drag

我有这个代码,我想遍历所有
com.abc.db.ConfigInfo
行,如果其中任何一行包含
cfgId
as
141
alert(cfgName)

已更新

alert(xml);
                        $(xml).find('list com\\.abc\\.db\\.ConfigInfo').each(function()
                        {
                            alert("enter the dragon");
                            if($(this).find('cfgId').text()=="141")  
                            alert($(this).find('cfgName').text()); 
                        }); 
我的XML

<list>
<com.abc.db.ConfigInfo>
<cfgId>83</cfgId>
<cfgName>test</cfgName>
</com.abc.db.ConfigInfo>
<com.abc.db.ConfigInfo>
<cfgId>102</cfgId>
<cfgName>cfgname1</cfgName>
</com.abc.db.ConfigInfo>
    </list>

83
测验
102
cfgname1

从根节点开始遍历

newXml = $.parseXML(xml)// parse your xml
$(newXml).find('list com.abc.db.ConfigInfo').each(function(){                            
if($(this).find('cfgId').text()=="141")                             
alert($(this).find('cfgName').text());                        
 }); 

你的代码在我看来是正确的。但是在xml示例中,没有任何
cfgId
作为
141
。这就是为什么您没有收到任何警报的一个很好的原因…

Sizzle(jQuery用于
.find
及其朋友的库)将把您的
“com.abc.db.ConfigInfo”
解释为“node
com
,带有类
abc
db
ConfigInfo


如果转义点有效,您可以尝试(
“list com\\.abc\\.db\\.ConfigInfo”
,双反斜杠,因为这些是JS字符串,您需要转义反斜杠),但如果可能,我建议您选择不带点的标记名。下划线应该更有效。

那么这有什么问题吗?@Vivek:它没有进入
每个
循环itself@Ovidiol:至少它应该进入我的循环,请参阅我更新的问题部分
xml
变量是怎么回事?您是否使用?l:我从服务器端响应var xml=client.responseText获取它;它看起来不像您正在使用的,您可以指定
数据类型:“xml”
。因此,您需要执行类似于
xmlDoc=$.parseXML(xml)的操作
然后使用
xmlDoc
遍历文档。我使用了您的方式,但我只能得到警报(xml);您还需要去掉
列表
位,因为jQuery将其作为根元素(正如@Vivek所说)。然后它对我有效,请参见:Vivek:no js error,我正在IE中尝试(如果有js错误,它会在左下角显示一个图标)使用
newXml=$.parseXML(xml)
,然后使用此newXml进行遍历