[OpenLayers-Dev] Format.XML, xmlns and QName
Tim Schaub
tschaub at opengeo.org
Thu Sep 2 13:13:16 EDT 2010
On 9/2/10 3:31 AM, Bart van den Eijnden (OSGIS) wrote:
> Hi list,
>
> I've been tracking down a problem in the SOS client, where the XML created
> had a value which is QName, i.e.:
>
> <resultModel>om:Measurement</resultModel>
>
> However, even though "om" is in the namespaces object of the format,
> xmlns:om was not added automatically.
>
> Is there a way to do this, similar to what is done for elements which are
> a QName, where things go okay automatically?
>
The problem is that without a schema, there is no way for the parser to
know the type of a text node. I don't have a good opinion of text nodes
of type QName, and I wish they would just go away. But, assuming that
is not going to happen, we could adopt a convention to manually add
xmlns attributes for each namespace alias in the namespaces object. I
think this is what other systems do (write an xmlns attribute at the
root for every namespace that might possibly appear in the document).
If the base XML format wrote xmlns attributes in it's write method,
other formats could get this for free if they call this method.
E.g. XML.js ~
write: function(node) {
for (var alias in this.namespaces) {
node.setAttribute("xmlns:" + alias, this.namespaces[alias]);
}
// ...
Would that do it for you?
Tim
> I now programmatically added the xmlns as a workaround.
>
> Index: lib/OpenLayers/Format/SOSGetObservation.js
> ===================================================================
> --- lib/OpenLayers/Format/SOSGetObservation.js (revision 10712)
> +++ lib/OpenLayers/Format/SOSGetObservation.js (working copy)
> @@ -104,6 +104,7 @@
> */
> write: function(options) {
> var node = this.writeNode("sos:GetObservation", options);
> + node.setAttribute("xmlns:om", this.namespaces.om);
> this.setAttributeNS(
> node, this.namespaces.xsi,
> "xsi:schemaLocation", this.schemaLocation
>
> Best regards,
> Bart
>
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
More information about the Dev
mailing list