internal void AddAttribute(InstanceAttribute attr) { if (firstAttribute == null) { firstAttribute = attr; } else { var next = firstAttribute; InstanceAttribute prev = null; while (next != null) { prev = next; next = next.NextAttribute; } prev.NextAttribute = attr; } }
private void GenerateInstanceAttribute(XmlSchemaAttribute attr, InstanceElement elem) { if (attr.Use == XmlSchemaUse.Prohibited || attr.AttributeSchemaType == null) { return; } var 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 { var next = firstAttribute; InstanceAttribute prev = null; while ( next != null ) { prev = next; next = next.NextAttribute; } prev.NextAttribute = attr; } }
private void GenerateInstanceAttribute(XmlSchemaAttribute attr, InstanceElement elem) { if ( attr.Use == XmlSchemaUse.Prohibited || attr.AttributeSchemaType == null ) { return; } var 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) { var whitespace = new char[] { ' ', '\t', '\n', '\r' }; InstanceAttribute attr = null; XmlSchemaAttribute anyAttr = null; var attributeWildCard = ct.AttributeWildcard; var attributes = ct.AttributeUses; var 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": var 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. "); } } }
private void GenerateAttributeWildCard(XmlSchemaComplexType ct, InstanceElement elem) { var whitespace = new char[] { ' ', '\t', '\n', '\r' }; InstanceAttribute attr = null; XmlSchemaAttribute anyAttr = null; var attributeWildCard = ct.AttributeWildcard; var attributes = ct.AttributeUses; var 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": var 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. "); } } }