Esempio n. 1
0
        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))
            {
                XPathResultType type = SchemaUtil.SimpleTypeToResultType(attribute.SimpleType);
                String          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");
        }
Esempio n. 2
0
        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");
                }
                String 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");
            }
            int index         = GetIndexedPropertyIndex(property);
            int xPathPosition = index + 1;

            return(new Pair <String, XPathResultType>('/' + prefix + property.PropertyNameAtomic + "[position() = " + xPathPosition + ']', type));
        }