0 Replies Latest reply on Mar 30, 2007 5:27 AM by WeisseDW

    XML and use of namespace

    WeisseDW
      Hello

      I have a question regarding the use of namespaces in ActionScript 3.

      In my application I receive an XML file from the server. The file has a namespace, so when I parse the file I need to specify the namespace:

      use namespace MyNamespace

      This means I need a file like the one below:

      package mypackage
      {
      public namespace MyNamespace = " http://www.foo.org";
      }


      No problem so far. But when I want to SEND an XML file, I would like to use the same namespace, with a prefix. How do I do that?

      This does NOT work:


      public static const ns:Namespace = new Namespace("prefix", " http://www.foo.org");

      default xml namespace = ns;
      var xml:XML = <root></root>;
      xml.addNamespace(ns);
      xml.appendChild(<child></child>);

      => result: the child node does NOT have a prefix.

      <prefix:root xmlns:intake=" http://www.foo.org">
      <child></child>
      </prefix:root>

      It has something to do with the URL of the namespace. If I change it so that it's different from namespace MyNamespace, then it does work:

      public static const ns:Namespace = new Namespace("prefix", " http://www.blabla.org");

      => result:

      <prefix:root xmlns:intake=" http://www.blabla.org">
      <prefix:child></prefix:child>
      </prefix:root>

      Does anyone know how I can add a prefix to all the nodes using the SAME URL?