private static Pair <string, XPathResultType> MakeAttributeProperty( SchemaItemAttribute attribute, Property property, XPathNamespaceContext ctx) { var prefix = ctx.LookupPrefix(attribute.Namespace); if (string.IsNullOrEmpty(prefix)) { prefix = ""; } else { prefix += ':'; } if (IsAnySimpleProperty(property)) { var type = SchemaUtil.SimpleTypeToResultType(attribute.SimpleType); var path = "/@" + prefix + property.PropertyNameAtomic; return(new Pair <string, XPathResultType>(path, type)); } if (IsAnyMappedProperty(property)) { throw new Exception("Mapped properties not applicable to attributes"); } throw new Exception("Indexed properties not applicable to attributes"); }
/// <summary> /// Returns the attributes within a collection. Most of the time, this will /// simply normalize the name and convert the structure into the resultant /// output type. /// </summary> /// <param name="xsModel">The xs model.</param> /// <param name="attributes">The attributes.</param> /// <returns></returns> internal IEnumerable <SchemaItemAttribute> GetAttributes( XmlSchema xsModel, XmlSchemaObjectCollection attributes) { foreach (var attr in attributes.Cast <XmlSchemaAttribute>()) { var name = attr.QualifiedName; if (name.IsEmpty) { if (attr.Form == XmlSchemaForm.Qualified) { name = new XmlQualifiedName(attr.Name, xsModel.TargetNamespace); } else { name = new XmlQualifiedName(attr.Name, null); } } var schemaType = ResolveSchemaType(xsModel, attr.SchemaTypeName); var itemAttribute = new SchemaItemAttribute( name.Namespace, name.Name, schemaType as XmlSchemaSimpleType, attr.SchemaTypeName.Name); yield return(itemAttribute); } }