Openlayers WFS返回结果解析:JS普通方式、JQuery方式

    技术2022-05-19  19

    源文地址:http://zazawind.3snavi.com/?p=63001

    转载请注明来源 http://zazawind.3snavi.com

    1.Openlayers 返回结果本身的xml 处理。

    var req = OpenLayers.Request.POST({                       url:        url,             data:        data,             success:    cbSearch,             failure:    cbSearchFailure,             scope:    this         });

    function cbSearch( response ){

        var xml = response.responseXML;

        if( xml == null ){

           return null;

        }

        var fms = xml.getElementsByTagName(“gml:featureMember”);

    var noData = " 暂无";

        for( var i=0; i<fms.length; i++ ){

           var rid = fms[i].getElementsByTagName("test:rid");

               if( rid.length>0 ){

                  rid = rid[0].firstChild.nodeValue;

               }else{

                  rid = noData;

               }

           var title = fms[i].getElementsByTagName("test:title");

               if( title.length>0 ){

                  title = title[0].firstChild.nodeValue;

               }else{

                  title = noData;

               }

        }

    }

    2.JQuery 处理openlayers 返回的处理结果方式。

    $(xml).find("gml//:featureMember).each( function( idx ){

      alert( idx );

    $( this ).find( "test//:layer" ).each( function (j) {

               var id = $( this ).children( "test//:id" ).text();

    });

    }

    需要注意的是命名空间与要素名称之间、冒号之前要加上//

    $(xml).find("a > b").each( function( idx ){

    });

    元素可以直接指定父子关系,找到子节点。

    源文地址:http://zazawind.3snavi.com/?p=63001

    转载请注明来源 http://zazawind.3snavi.com


    最新回复(0)