Files
iD/js/iD/XML.js
T

58 lines
2.0 KiB
JavaScript

iD.XML = {
mapping: function(entity) {
if (this.mappings[entity.type]) {
return this.mappings[entity.type](entity);
}
},
decode: function(s) {
return s.replace(/>/g,'>').
replace(/</g,'&lt;').
replace(/"/g,'&quot;');
},
mappings: {
node: function(entity) {
return iD.XML.decode((new XMLSerializer()).serializeToString(
JXON.unbuild({
node: {
'@id': entity.id,
'@lat': entity.lat,
'@lon': entity.lon,
'tag': _.map(entity.tags, function(k, v) {
return {
keyAttributes: {
k: k,
v: v
}
};
})
}
})
));
},
way: function(entity) {
return iD.XML.decode(
(new XMLSerializer()).serializeToString(
JXON.unbuild({
way: {
'@id': entity.id,
'nd': entity.children.map(function(e) {
return {
keyAttributes: {
ref: e.id
}
};
}),
'tag': _.map(entity.tags, function(k, v) {
return {
keyAttributes: {
k: k,
v: v
}
};
})
}
})));
}
}
};