使用JQuery获取HTML标记中的值

使用JQuery获取HTML标记中的值,jquery,xml,Jquery,Xml,这就是我试图解析的XML <BOLETIN> <localidad>Palencia</localidad> <predicciones_timestamp>07-10-2011 00h</predicciones_timestamp> <altitud>797</altitud> <fecha>2011-10-07 <titulo1>Día</titulo1

这就是我试图解析的XML

<BOLETIN>
<localidad>Palencia</localidad>
<predicciones_timestamp>07-10-2011 00h</predicciones_timestamp>
<altitud>797</altitud>
    <fecha>2011-10-07
        <titulo1>Día</titulo1>
        <cielo1>Cubierto</cielo1>

        <titulo2>Noche</titulo2>
        <cielo2>N-Cubierto</cielo2>
        ....
    </fecha>
使用类似于:

var fech = $(this).find('fecha');
它不起作用。它将fecha作为Object类型的对象。如果我尝试:

var fech = $(this).find('fecha').text();
fech的值为空

如何从XML中获取值2011-10-07

非常感谢,
VM

我建议您查看JQuery中的方法-在XML中查找/更新信息比使用
find()
each()

要容易得多。谢谢FrozenFlame,但我无法更改XML,它来自web。请检查我找到的新解决方案。希望它能帮助Hanks ManseUK,但我在JQuery web上找不到解决这个问题的方法。@VictorMartínezGrandmontagne您的XML不是有效的XML-因此使用JQuery中的标准解析例程解析XML将不起作用-您需要提取字符串-可能使用javascript中的子字符串方法
var fech = $(this).find('fecha').text();
 <BOLETIN>
<localidad>Palencia</localidad>
<predicciones_timestamp>07-10-2011 00h</predicciones_timestamp>
<altitud>797</altitud>
    <fecha date='2011-10-07'>
        <titulo1>Día</titulo1>
        <cielo1>Cubierto</cielo1>

        <titulo2>Noche</titulo2>
        <cielo2>N-Cubierto</cielo2>
        ....
    </fecha>



 $(xml).find('BOLETIN').each(function(){
 var localidad = $(this).find('localidad').text();
 $( "#localidad" ).append( localidad );                      
 $(this).find('fecha').each(function(){
  var date  = $(this).attr('date');
  var titulo1 = $(this).find('titulo1').text();
  var cielo1 = $(this).find('cielo1').text();
$("fecha")
        .clone()    //clone the element
        .children() //select all the children
        .remove()   //remove all the children
        .end()  //again go back to selected element
        .text();    //get the text of element