[OpenLayers-Dev] Format.XML, xmlns and QName

Xurxo Mendez xmendez at udc.es
Fri Sep 3 10:01:54 EDT 2010


Hi all,

I was working on that and facing the same problem, and I've just submitted a
patch (see http://trac.openlayers.org/attachment/ticket/2819/2819.patch)
that I think fixes that. It adds all the xmlns attributes that exist in the
namespaces object of the format, but avoids doing so when, for example
adding the xmlns attribute for "foo" namespace, the node itself of any of
its attributes has the namespaceURI property set to this.namespaces["foo"].

I tested it in Firefox 3.6.8. I found that the behavior
XMLSerializer.serializeToString(doc) lead to the addition of "xmlns:foo=bar"
attributes for those nodes/attributes in the node that had
nodeName="foo:name" and namespaceURI="bar".

Best regards,

Xurxo Méndez Pérez

2010/9/2 Bart van den Eijnden <bartvde at osgis.nl>

> Hey Tim,
>
> right that solution would work for me.
>
> I've opened up:
> http://trac.openlayers.org/ticket/2819
>
> Best regards,
> Bart
>
> --
> Looking for flexible support on OpenLayers or GeoExt? Please check out
> http://www.osgis.nl/support.html
>
> Bart van den Eijnden
> OSGIS
> bartvde at osgis.nl
>
> On Sep 2, 2010, at 7:13 PM, Tim Schaub wrote:
>
> > 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.
> > _______________________________________________
> > Dev mailing list
> > Dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/openlayers-dev
> >
>
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100903/99df036f/attachment-0001.html


More information about the Dev mailing list