Exemple #1
0
        public void WriteXsiTypeAttribute(XmlWriteAdaptor adaptor)
        {
            const string method = "WriteXsiTypeAttribute";

            if (adaptor == null)
            {
                throw new NullParameterException(GetType(), method, "adaptor");
            }

            string typeName;

            if (_namespace.Length > 0)
            {
                // Find the existing prefix for this namespace or write a new namespace declaration.

                string prefix = adaptor.LookupPrefix(_namespace);

                if (prefix == null)
                {
                    prefix = GetNameFromFullNameUnchecked(_namespace).ToLower();
                    adaptor.WriteNamespace(prefix, _namespace);
                }

                typeName = prefix + ":" + _name;
            }
            else
            {
                typeName = _name;
            }

            // Append the version with a "-", which is valid in a QName.

            if (_version != null)
            {
                typeName += "-" + _version;
            }

            // Write xsi:type.

            adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix,
                                   Constants.Xsi.Namespace, typeName);
        }