Permalink
Browse files

fix error that appears when using xml2js 0.2.0

  • Loading branch information...
1 parent d96f460 commit 9a35f9b88a060fe7d3ff6aa07e8d98a17cf718ed @michielbdejong committed Oct 3, 2012
Showing with 29 additions and 24 deletions.
  1. +29 −24 parser/xrd.js
View
@@ -28,34 +28,39 @@ exports.parse = function(url, docRel, headers, content, cb) {
data2.Property = [data2.Property];
}
}
+ if(data2.XRD) {
+ data2=data2.XRD;
+ }
if(!data2.Link) {
console.log('no .Link:');
console.log(data2);
- } else if(data2.Link['@']) {
- data2.Link = [data2.Link];
- }
- for(var i=0; i<data2.Link.length; i++) {
- if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/avatar') {
- obj.images.avatar = data2.Link[i]['@'].href;
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'describedby' && data2.Link[i]['@'].type == 'application/rdf+xml') {
- obj.documents[data2.Link[i]['@'].href] = 'describedby';
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0') {
- if(data2.Link[i]['@'].href != 'http://www-opensocial.googleusercontent.com/api/people/') {//bug in that specific node
- obj.documents[data2.Link[i]['@'].href] = 'poco';
- }
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://microformats.org/profile/hcard') {
- obj.documents[data2.Link[i]['@'].href] = 'hcard';
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0#me') {
- obj.documents[data2.Link[i]['@'].href] = 'poco-me';
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'lrdd') {
- var templateParts = data2.Link[i]['@'].template.split('{uri}');
- if(url.indexOf('/.well-known/host-meta?resource=acct:')) {
- obj.documents[templateParts[0]+url.substring(url.indexOf('/.well-known/host-meta?resource=acct:')+'/.well-known/host-meta?resource='.length)+templateParts[1]] = 'lrdd';
+ } else {
+ if(data2.Link['@']) {
+ data2.Link = [data2.Link];
+ }
+ for(var i=0; i<data2.Link.length; i++) {
+ if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/avatar') {
+ obj.images.avatar = data2.Link[i]['@'].href;
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'describedby' && data2.Link[i]['@'].type == 'application/rdf+xml') {
+ obj.documents[data2.Link[i]['@'].href] = 'describedby';
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0') {
+ if(data2.Link[i]['@'].href != 'http://www-opensocial.googleusercontent.com/api/people/') {//bug in that specific node
+ obj.documents[data2.Link[i]['@'].href] = 'poco';
+ }
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://microformats.org/profile/hcard') {
+ obj.documents[data2.Link[i]['@'].href] = 'hcard';
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0#me') {
+ obj.documents[data2.Link[i]['@'].href] = 'poco-me';
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'lrdd') {
+ var templateParts = data2.Link[i]['@'].template.split('{uri}');
+ if(url.indexOf('/.well-known/host-meta?resource=acct:')) {
+ obj.documents[templateParts[0]+url.substring(url.indexOf('/.well-known/host-meta?resource=acct:')+'/.well-known/host-meta?resource='.length)+templateParts[1]] = 'lrdd';
+ }
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/profile-page') {
+ obj.tools[data2.Link[i]['@'].href] = 'R';
+ } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://schemas.google.com/g/2010#updates-from') {
+ obj.tools[data2.Link[i]['@'].href] = 'S';
}
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/profile-page') {
- obj.tools[data2.Link[i]['@'].href] = 'R';
- } else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://schemas.google.com/g/2010#updates-from') {
- obj.tools[data2.Link[i]['@'].href] = 'S';
}
}
cb(null, obj);

0 comments on commit 9a35f9b

Please sign in to comment.