1 Reply Latest reply on May 2, 2008 3:09 AM by angie_mc

    Creating XML object with namespaces

    angie_mc Level 1
      I'm trying to create the following XML
      <xs:schema id='MySchema' xmlns:xs=' http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
      <xs:element name='MySchema' msdata:IsDataSet='true' msdata:UseCurrentLocale='true'/>
      </xs:schema>

      Following the documentation it appears that the following code should do the trick

      private const xs:Namespace = new Namespace(" http://www.w3.org/2001/XMLSchema");
      private const msdata:Namespace = new Namespace("urn:schemas-microsoft-com:xml-msdata");

      var testXml:XML = <schema></schema>;
      testXml.addNamespace(xs);
      testXml.addNamespace(msdata);
      testXml.@id = "MySchema";
      testXml.xs::element.@name = "MySchema";
      testXml.element.@msdata::IsDataSet = true;
      testXml.element.@msdata::UseCurrentLocale = true;

      However, this results in the following XML
      <schema id="PERSONDETAILS">
      <element name="PERSONDETAILS" xmlns=" http://www.w3.org/2001/XMLSchema"/>
      <element IsDataSet="true" UseCurrentLocale="true" xmlns="urn:schemas-microsoft-com:xml-msdata"/>
      </schema>

      Can anyone tell me what I'm doing wrong? Thanks