与谷歌的Picasa API和jQuery开发的简单XML解析 [英] Simple XML parsing with Google Picasa API and JQuery

查看:127
本文介绍了与谷歌的Picasa API和jQuery开发的简单XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始寻找到谷歌的Picasa API进行照片数据,它将为您提供有关相册和照片信息一个大的XML文件。

I'm starting to look into Google's Picasa API for photo data, which provides you with a big XML file with info about albums and photos.

我在做一些快速和肮脏的测试解析与jQuery XML文件(这是本地保存到我的硬盘驱动器现在),并拉出专辑的ID,存储为gphoto:标识标签,并在一个div显示出来:

I'm doing some quick and dirty tests to parse the XML file (which is saved locally to my hard drive for now) with JQuery and pull out the album id's, which are stored as "gphoto:id" tags, and display them in a div:

$(document).ready(function() {
$.get(
    'albums.xml',
    function(data) 
    {
        $(data).find('entry').each(function() 
        {
            var albumId = $(this).children('gphoto:id').text();
            $('#photos').append(albumId + '<br />');
        })
    })
})

我收到以下错误控制台:

I'm getting the following error in the console:

的jquery.js:3321 - 未捕获的语法错误,无法识别的前pression:语法错误,无法识别的前pression:ID

这将与XML文件中的其它标签(如标题,作者,更新等)的工作,但我想明白是怎么回事。是否有做结肠?gphoto:ID,不知何故

This will work with other tags in the XML file (such as title, author, updated, etc.), but I'm trying to understand what's going on here. Does it have to do with the colon in "gphoto:id", somehow?

您可以看到从Picasa相册的XML文件看起来像此处的http://$c$c.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#ListAlbumPhotos

You can see what an XML file from a Picasa album looks like here: http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#ListAlbumPhotos

推荐答案

<一个href=\"http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces/1901903#1901903\">This回答解决了这个问题。我把它通过更换这个工作:

This answer solved the problem. I got it to work by replacing this:

var albumId = $(this).children('gphoto:id').text();

本:

var albumId = $(this).find('[nodeName=gphoto:id]').text();

这篇关于与谷歌的Picasa API和jQuery开发的简单XML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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