4 Replies Latest reply on Oct 26, 2007 10:08 PM by Vishwas Gagrani

    How to specify XML declaration in an XML Variable

      I had posted this question in the Flex Builder discussion, but I am not sure if that was the right board, so posting it again here:

      I need to set the XML declaration for my XML variable as follows:
      var employees:XML =
      <?xml version="1.0" encoding="utf-8"?>
      <employee ssn="123-123-1234">
      <name first="John" last="Doe"/>
      <street>11 Main St.</street>
      <city>San Francisco</city>
      <employee ssn="789-789-7890">
      <name first="Mary" last="Roe"/>
      <street>99 Broad St.</street>

      However, if I specify <?xml version="1.0" encoding="utf-8"?>, I get a design time and compile error. If I remove it it works fine. But the server to which I send this XML is expecting the declaration. How can I set the declaration?

      Any help or pointer is appreciated.
        • 1. Re: How to specify XML declaration in an XML Variable
          TheTyrant Level 1
          I'm having a similar problem. I'm retrieving my XML from an HTTPService, then modifying it, and re-posting the xml as the request property of another HTTPService. The problem is that flex strips out my <?xml?> declaration. I've tried re-adding it manually through string manipulation, but it still strips it out. My post is failing because of this. Anyone know the correct way to get flex to put the xml declaration back on the top of my XML object?
          • 2. Re: How to specify XML declaration in an XML Variable
            peterent Level 2
            I've read and sent XML data quite a bit and I've never had this problem. First, you are correct that you cannot include the XML header in the XML declaration. Likewise, when you receive XML data from the server it will not have that header.

            How are you posting your XML back to the server?
            • 4. Re: How to specify XML declaration in an XML Variable
              Vishwas Gagrani Level 1
              I am not able to load the xml. Can anybody figure out the problem :

              I have used a LoadXML class :
              package {

              import flash.display.*;

              import flash.events.*;

              import flash.net.*;

              // Demonstrates the code required to load external XML

              public class LoadXML extends Sprite {

              // The property that will eventually contain the loaded XML

              private var novel:XML;

              // The object used to load the XML

              private var urlLoader:URLLoader;

              // Constructor

              public function LoadXML () {

              // Specify the location of the external XML

              var urlRequest:URLRequest = new URLRequest("novel.xml");

              // Create an object that can load external text data

              urlLoader = new URLLoader();

              // Register to be notified when the XML finishes loading

              urlLoader.addEventListener(Event.COMPLETE, completeListener);

              // Load the XML



              // Method invoked automatically when the XML finishes loading

              private function completeListener(e:Event):void {

              // The string containing the loaded XML is stored in the URLLoader

              // object's data property (urlLoader.data). To create a new XML

              // instance from that loaded string, we pass it to the XML constructor

              novel = new XML(urlLoader.data);

              trace(novel.toXMLString()); // Display the loaded XML, now converted

              // to an XML object




              And in main.mxml :

              myXml = new LoadXml ;

              trace ( myXml.novel ) ;

              The output is errenous