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;
     }
 }
Exemplo n.º 2
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;
            }
        }
Exemplo 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);
        }
 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;
     }
 }
Exemplo n.º 5
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. ");
                }
            }
        }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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. ");
                }
            }
        }