- doc = XML::Document.new
- doc.encoding = 'UTF-8'
- root = XML::Node.new 'osm'
- root['version'] = '0.4'
- root['generator'] = 'OpenStreetMap server'
- doc.root = root
- el1 = XML::Node.new 'node'
- el1['id'] = self.id.to_s
- el1['lat'] = self.latitude.to_s
- el1['lon'] = self.longitude.to_s
- split_tags(el1, self.tags)
- el1['visible'] = self.visible.to_s
- el1['timestamp'] = self.timestamp.xmlschema
- root << el1
- return doc
+ doc = OSM::API.new.get_xml_doc
+ doc.root << to_xml_node
+ doc
+ end
+
+ def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
+ el = XML::Node.new "node"
+ el["id"] = id.to_s
+
+ add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
+
+ if visible?
+ el["lat"] = lat.to_s
+ el["lon"] = lon.to_s
+ end
+
+ add_tags_to_xml_node(el, node_tags)
+
+ el
+ end
+
+ def tags_as_hash
+ tags
+ end
+
+ def tags
+ @tags ||= Hash[node_tags.collect { |t| [t.k, t.v] }]
+ end
+
+ attr_writer :tags
+
+ def add_tag_key_val(k, v)
+ @tags ||= {}
+
+ # duplicate tags are now forbidden, so we can't allow values
+ # in the hash to be overwritten.
+ raise OSM::APIDuplicateTagsError.new("node", id, k) if @tags.include? k
+
+ @tags[k] = v
+ end
+
+ ##
+ # are the preconditions OK? this is mainly here to keep the duck
+ # typing interface the same between nodes, ways and relations.
+ def preconditions_ok?
+ in_world?
+ end
+
+ ##
+ # dummy method to make the interfaces of node, way and relation
+ # more consistent.
+ def fix_placeholders!(_id_map, _placeholder_id = nil)
+ # nodes don't refer to anything, so there is nothing to do here