2 Replies Latest reply on Jun 9, 2008 12:28 PM by sworisbreathing

    removeNamespace is not removing the namespace

    SoxFan33
      Can anyone shed any light on why code that successfully removed a namespace from an XML object in Flex 2 now will not do so in Flex 3?

      The code is essentially as follows:

      var tmp:XML = node.ns::DesiredNode[0];
      tmp = tmp.removeNamespace(ns);

      However a trace of tmp outputs the xml content that still has 'ns' as its namespace. Also, the namespaceDeclarations.length is 0 for tmp both before and after removing the namespace, even though the namespace is clearly present.

      Any help would be greatly appreciated. Thanks.
        • 1. removeNamespace is not removing the namespace
          invokeMe Level 1
          I am having a similar problem... According to the docs...

          quote:

          The removeNamespace() method does not remove a namespace if it is referenced by the object's qualified name or the qualified name of the object's attributes.


          This is the case in your example. The problem is I can't figure out how to get around this limitation (not even really sure why it exists in the first place).

          Changing the QName of the topmost element to a localName and then calling removeNamespace() works but only for the topmost element; any children that also have the namespace as a part of their QName will still have it.

          Does anyone know how to recursively remove a namespace that is part of the elements QName?
          • 2. removeNamespace is not removing the namespace
            sworisbreathing
            I'm having a similar problem, the cause of which is rather interesting.

            I'm using an HTTPService object to hit web services that return their responses in XML format. In this particular case, the returned XML document is a wrapper (I won't call it an envelope because I don't want to give the impression that I'm using SOAP here, but it's the same idea) containing one or more XML documents. Each XML document has its own doctype definition and gets parsed further down the line in my application. The top-level element uses a namespace declaration that is not used by the individual documents.

            The problem I'm having is that when I parse the result in my HTTPService result event handler (I will point out here that I'm using e4x, in case that makes a difference), Flex' XML parser copies the namespace declaration into every child element, regardless of whether that namespace declaration was in the XML returned by the server.

            The server returns the following document tree:
            <fooWrapper xmlns:xsi="some/crazy/url" xsi:schemaLocation="some/schema/location">
            <barDocument>...</barDocument>
            <barDocument>...</barDocument>
            </fooWrapper>

            The HTTPService result event handler sees this:
            <fooWrapper xmlns:xsi="some/crazy/url" xsi:schemaLocation="some/schema/location">
            <barDocument xmlns:xsi="some/crazy/url">...</barDocument>
            <barDocument xmlns:xsi="some/crazy/url">...</barDocument>
            </fooWrapper>

            So now I'm trying to remove the erroneous "xmlns:xsi" declarations from all my barDocument elements. You'd think that just calling removeNamespace() directly on each child would work, but it doesn't. I think it has something to do with how Flex handles the e4x result format. The workaround that I found was to make a new XML object using the result of each document's toXMLString() output as shown: