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"); }
private static Pair <string, XPathResultType> MakeElementProperty( SchemaElement schemaElement, Property property, XPathNamespaceContext ctx, bool isAlone, bool isDynamic, string defaultNamespacePrefix) { XPathResultType type; if (isDynamic) { type = XPathResultType.Any; } else if (schemaElement is SchemaElementSimple) { var element = (SchemaElementSimple)schemaElement; type = SchemaUtil.SimpleTypeToResultType(element.SimpleType); } else { var complex = (SchemaElementComplex)schemaElement; type = XPathResultType.Any; //if (complex.OptionalSimpleType != null) //{ // type = SchemaUtil.SimpleTypeToQName(complex.OptionalSimpleType); //} //else //{ // // The result is a node // type = XPathResultType.Any; //} } var prefix = isDynamic ? defaultNamespacePrefix : ctx.LookupPrefix(schemaElement.Namespace); if (string.IsNullOrEmpty(prefix)) { prefix = string.Empty; } else { prefix += ':'; } if (IsAnySimpleProperty(property)) { if (!isDynamic && schemaElement.IsArray && !isAlone) { throw new PropertyAccessException( "Simple property not allowed in repeating elements at '" + schemaElement.Name + "'"); } return(new Pair <string, XPathResultType>('/' + prefix + property.PropertyNameAtomic, type)); } if (IsAnyMappedProperty(property)) { if (!isDynamic && !schemaElement.IsArray) { throw new PropertyAccessException( "Element " + property.PropertyNameAtomic + " is not a collection, cannot be used as mapped property"); } var key = GetMappedPropertyKey(property); return(new Pair <string, XPathResultType>( '/' + prefix + property.PropertyNameAtomic + "[@id='" + key + "']", type)); } if (!isDynamic && !schemaElement.IsArray) { throw new PropertyAccessException( "Element " + property.PropertyNameAtomic + " is not a collection, cannot be used as mapped property"); } var index = GetIndexedPropertyIndex(property); var xPathPosition = index + 1; return(new Pair <string, XPathResultType>( '/' + prefix + property.PropertyNameAtomic + "[position() = " + xPathPosition + ']', type)); }