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); }
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. "); } } }