使用 Google Picasa API 和 JQuery 进行简单的 XML 解析 [英] Simple XML parsing with Google Picasa API and JQuery

查看:19
本文介绍了使用 Google Picasa API 和 JQuery 进行简单的 XML 解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始研究用于照片数据的 Google 的 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 文件(目前保存在本地硬盘中)并提取存储为gphoto:id"标签的专辑 ID,以及在 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 - 未捕获的语法错误,无法识别的表达式:语法错误,无法识别的表达式: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://code.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

推荐答案

这个答案解决了这个问题.我通过替换它来让它工作:

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

这篇关于使用 Google Picasa API 和 JQuery 进行简单的 XML 解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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