Exemplo n.º 1
0
        private void WriteTableAttributes(ArrayList atts)
        {
            //Then a list of attributes
            foreach (DataColumn col in atts)
            {
                w.WriteStartElement("xs", "attribute", xmlnsxs);

                string name = XmlHelper.Encode(col.ColumnName);
                if (col.Namespace != String.Empty)
                {
                    w.WriteAttributeString("form", "qualified");
                    string prefix = col.Prefix == String.Empty ? "app" + additionalNamespaces.Count : col.Prefix;
                    name = prefix + ":" + name;
                    // FIXME: Handle prefix mapping correctly.
                    additionalNamespaces [prefix] = col.Namespace;
                }
                w.WriteAttributeString("name", name);

                AddExtendedPropertyAttributes(
                    col.ExtendedProperties);

                if (col.ReadOnly)
                {
                    w.WriteAttributeString(
                        XmlConstants.MsdataPrefix,
                        XmlConstants.ReadOnly,
                        XmlConstants.MsdataNamespace,
                        "true");
                }

                if (col.MaxLength < 0)
                {
                    // otherwise simpleType is written later
                    w.WriteStartAttribute("type", String.Empty);
                    WriteQName(MapType(col.DataType));
                    w.WriteEndAttribute();
                }

                if (!col.AllowDBNull)
                {
                    w.WriteAttributeString("use", "required");
                }
                if (col.DefaultValue != DataColumn.GetDefaultValueForType(col.DataType))
                {
                    w.WriteAttributeString("default",
                                           DataSet.WriteObjectXml(col.DefaultValue));
                }

                if (col.MaxLength > -1)
                {
                    WriteSimpleType(col);
                }

                w.WriteEndElement();                  // attribute
            }
        }
Exemplo n.º 2
0
 private void AddExtendedPropertyAttributes(PropertyCollection props)
 {
     // add extended properties to xs:element
     foreach (DictionaryEntry de in props)
     {
         w.WriteStartAttribute(
             XmlConstants.MspropPrefix,
             XmlConvert.EncodeName(de.Key.ToString()),
             XmlConstants.MspropNamespace);
         if (de.Value != null)
         {
             w.WriteString(
                 DataSet.WriteObjectXml(de.Value));
         }
         w.WriteEndAttribute();
     }
 }
Exemplo n.º 3
0
        private void WriteTableTypeParticles(DataColumn col)
        {
            w.WriteStartElement("xs", "element", xmlnsxs);
            w.WriteAttributeString("name", XmlHelper.Encode(col.ColumnName));

            if (col.ColumnName != col.Caption && col.Caption != String.Empty)
            {
                w.WriteAttributeString(
                    XmlConstants.MsdataPrefix,
                    XmlConstants.Caption,
                    XmlConstants.MsdataNamespace,
                    col.Caption);
            }

            if (col.AutoIncrement == true)
            {
                w.WriteAttributeString(
                    XmlConstants.MsdataPrefix,
                    XmlConstants.AutoIncrement,
                    XmlConstants.MsdataNamespace,
                    "true");
            }

            if (col.AutoIncrementSeed != 0)
            {
                w.WriteAttributeString(

                    XmlConstants.MsdataPrefix,
                    XmlConstants.AutoIncrementSeed,
                    XmlConstants.MsdataNamespace,
                    XmlConvert.ToString(col.AutoIncrementSeed));
            }

            if (col.AutoIncrementStep != 1)
            {
                w.WriteAttributeString(

                    XmlConstants.MsdataPrefix,
                    XmlConstants.AutoIncrementStep,
                    XmlConstants.MsdataNamespace,
                    XmlConvert.ToString(col.AutoIncrementStep));
            }

            if (!DataColumn.GetDefaultValueForType(col.DataType).Equals(col.DefaultValue))
            {
                w.WriteAttributeString("default",
                                       DataSet.WriteObjectXml(col.DefaultValue));
            }

            if (col.ReadOnly)
            {
                w.WriteAttributeString(
                    XmlConstants.MsdataPrefix,
                    XmlConstants.ReadOnly,
                    XmlConstants.MsdataNamespace,
                    "true");
            }

            XmlQualifiedName typeQName = null;

            if (col.MaxLength < 0)
            {
                w.WriteStartAttribute("type", String.Empty);
                typeQName = MapType(col.DataType);
                WriteQName(typeQName);
                w.WriteEndAttribute();
            }

            if (typeQName == XmlConstants.QnString &&
                col.DataType != typeof(string) &&
                col.DataType != typeof(char))
            {
                w.WriteStartAttribute(
                    XmlConstants.MsdataPrefix,
                    XmlConstants.DataType,
                    XmlConstants.MsdataNamespace);
                string runtimeName = col.DataType.AssemblyQualifiedName;
                w.WriteString(runtimeName);
                w.WriteEndAttribute();
            }

            if (col.AllowDBNull)
            {
                w.WriteAttributeString("minOccurs", "0");
            }

            //writer.WriteAttributeString (XmlConstants.MsdataPrefix,
            //                            XmlConstants.Ordinal,
            //                            XmlConstants.MsdataNamespace,
            //                            col.Ordinal.ToString ());

            // Write SimpleType if column have MaxLength
            if (col.MaxLength > -1)
            {
                WriteSimpleType(col);
            }

            AddExtendedPropertyAttributes(col.ExtendedProperties);

            w.WriteEndElement();              // sequence
        }