Esempio n. 1
0
        private void ProcessElementAttrs(InstanceElement elem)
        {
            if (elem.XsiType != XmlQualifiedName.Empty)
            {
                if (elem.XsiType.Namespace != string.Empty)
                {
                    _writer.WriteStartAttribute("xsi", "type", null);
                    _writer.WriteQualifiedName(elem.XsiType.Name, elem.XsiType.Namespace);
                    _writer.WriteEndAttribute();
                }
                else
                {
                    _writer.WriteAttributeString("xsi", "type", null, elem.XsiType.Name);
                }
            }

            InstanceAttribute attr = elem.FirstAttribute;

            while (attr != null)
            {
                if (attr.AttrUse != XmlSchemaUse.Prohibited)
                {
                    if (attr.QualifiedName.Namespace == NsXml)
                    {
                        _writer.WriteStartAttribute("xml", attr.QualifiedName.Name, attr.QualifiedName.Namespace);
                    }
                    else
                    {
                        _writer.WriteStartAttribute(attr.QualifiedName.Name, attr.QualifiedName.Namespace);
                    }
                    if (attr.HasDefault)
                    {
                        _writer.WriteString(attr.DefaultValue);
                    }
                    else if (attr.IsFixed)
                    {
                        _writer.WriteString(attr.FixedValue);
                    }
                    else
                    {
                        _writer.WriteString(attr.ValueGenerator.GenerateValue());
                    }
                    _writer.WriteEndAttribute();
                }
                attr = attr.NextAttribute;
            }
        }
Esempio n. 2
0
 internal void AddAttribute(InstanceAttribute attr)
 {
     if (firstAttribute == null)
     {
         firstAttribute = attr;
     }
     else
     {
         InstanceAttribute next = firstAttribute;
         InstanceAttribute prev = null;
         while (next != null)
         {
             prev = next;
             next = next.NextAttribute;
         }
         prev.NextAttribute = attr;
     }
 }
Esempio n. 3
0
        private void GenerateInstanceAttribute(XmlSchemaAttribute attr, InstanceElement elem)
        {
            if (attr.Use == XmlSchemaUse.Prohibited || attr.AttributeSchemaType == null)
            {
                return;
            }
            InstanceAttribute iAttr = new InstanceAttribute(attr.QualifiedName);

            iAttr.DefaultValue   = attr.DefaultValue;
            iAttr.FixedValue     = attr.FixedValue;
            iAttr.AttrUse        = attr.Use;
            iAttr.ValueGenerator = XmlValueGenerator.CreateGenerator(attr.AttributeSchemaType.Datatype, _listLength);
            if (iAttr.ValueGenerator != null && iAttr.ValueGenerator.Prefix == null)
            {
                iAttr.ValueGenerator.Prefix = iAttr.QualifiedName.Name;
            }
            elem.AddAttribute(iAttr);
        }
Esempio n. 4
0
        private void GenerateAttributeWildCard(XmlSchemaComplexType ct, InstanceElement elem)
        {
            char[]             whitespace = new char[] { ' ', '\t', '\n', '\r' };
            InstanceAttribute  attr       = null;
            XmlSchemaAttribute anyAttr    = null;

            XmlSchemaAnyAttribute attributeWildCard = ct.AttributeWildcard;
            XmlSchemaObjectTable  attributes        = ct.AttributeUses;

            string namespaceList = attributeWildCard.Namespace;

            if (namespaceList == null)
            {
                namespaceList = "##any";
            }
            if (attributeWildCard.ProcessContents == XmlSchemaContentProcessing.Skip || attributeWildCard.ProcessContents == XmlSchemaContentProcessing.Lax)
            {
                if (namespaceList == "##any" || namespaceList == "##targetNamespace")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", _rootTargetNamespace));
                }
                else if (namespaceList == "##local")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", string.Empty));
                }
                else if (namespaceList == "##other")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", "otherNS"));
                }
                if (attr != null)
                {
                    attr.ValueGenerator = XmlValueGenerator.AnySimpleTypeGenerator;
                    elem.AddAttribute(attr);
                    return;
                }
            }
            switch (namespaceList)
            {
            case "##any":
            case "##targetNamespace":
                anyAttr = GetAttributeFromNS(_rootTargetNamespace, attributes);
                break;

            case "##other":
                XmlSchema anySchema = GetParentSchema(attributeWildCard);
                anyAttr = GetAttributeFromNS(anySchema.TargetNamespace, true, attributes);
                break;

            case "##local":                     //Shd get local elements in some schema
                anyAttr = GetAttributeFromNS(string.Empty, attributes);
                break;

            default:
                foreach (string ns in attributeWildCard.Namespace.Split(whitespace))
                {
                    if (ns == "##local")
                    {
                        anyAttr = GetAttributeFromNS(string.Empty, attributes);
                    }
                    else if (ns == "##targetNamespace")
                    {
                        anyAttr = GetAttributeFromNS(_rootTargetNamespace, attributes);
                    }
                    else
                    {
                        anyAttr = GetAttributeFromNS(ns, attributes);
                    }
                    if (anyAttr != null)
                    {                             //Found match
                        break;
                    }
                }
                break;
            }
            if (anyAttr != null)
            {
                GenerateInstanceAttribute(anyAttr, elem);
            }
            else
            {             //Write comment in generated XML that match for wild card cd not be found.
                if (elem.Comment.Length == 0)
                {         //For multiple attribute wildcards in the same element, generate comment only once
                    elem.Comment.Append(" Attribute Wild card could not be matched. Generated XML may not be valid. ");
                }
            }
        }