Example #1
0
 internal void Init()
 {
     _nodeType     = XmlNodeType.None;
     _depth        = 0;
     _nodeValue    = new QNameValue();
     _attributeTop = -1;
 }
Example #2
0
 internal void Init(XmlNodeType nodeType, int depth)
 {
     _nodeType     = nodeType;
     _depth        = depth;
     _nodeValue    = new QNameValue();
     _attributeTop = -1;
 }
Example #3
0
 internal FINode()
 {
     _nodeType     = XmlNodeType.None;
     _depth        = 0;
     _attributeTop = -1;
     _attributes   = new QNameValue[GROW_SIZE];
 }
Example #4
0
            internal void SetAttributes(QNameValue[] nodeList, int count)
            {
                if (_attributes.Length < count)
                {
                    _attributes = new QNameValue[count];
                }

                Array.Copy(nodeList, _attributes, count);
                _attributeTop = count - 1;
            }
Example #5
0
            internal void AddAttribute(QNameValue attrNode)
            {
                if (_attributeTop == (_attributes.Length - 1))
                {
                    QNameValue[] destinationArray = new QNameValue[_attributes.Length + GROW_SIZE];
                    if (_attributeTop > 0)
                    {
                        Array.Copy(_attributes, destinationArray, _attributeTop + 1);
                    }

                    _attributes = destinationArray;
                }

                _attributeTop++;
                _attributes[_attributeTop] = attrNode;
            }
Example #6
0
        //  internal constructor from a QNameValue

        internal QName(QNameValue q)
        {
            this.uri    = q.getNamespaceURI();
            this.prefix = q.getPrefix();
            this.local  = q.getLocalName();
        }
Example #7
0
 public NotationValue(QNameValue name)
 {
     Prefix = name.Prefix;
     LocalName = name.LocalName;
     NamespaceUri = name.NamespaceUri;
 }
Example #8
0
        //  internal constructor from a QNameValue

        internal QName(QNameValue q)
        {
            this.uri = q.getNamespaceURI();
            this.prefix = q.getPrefix();
            this.local = q.getLocalName();
        }
Example #9
0
        public static object GetTypedValue(this XPathItem item)
        {
            XPathNavigator nav = item as XPathNavigator;

            if (nav == null)
            {
                return(item.TypedValue);
            }
            IXmlSchemaInfo schemaInfo = nav.SchemaInfo;

            if (schemaInfo == null || schemaInfo.SchemaType == null)
            {
                switch (nav.NodeType)
                {
                case XPathNodeType.Comment:
                case XPathNodeType.ProcessingInstruction:
                case XPathNodeType.Namespace:
                    return(nav.Value);

                default:
                    return(new UntypedAtomic(nav.Value));
                }
            }
            XmlTypeCode typeCode = schemaInfo.SchemaType.TypeCode;

            if (typeCode == XmlTypeCode.AnyAtomicType && schemaInfo.MemberType != null)
            {
                typeCode = schemaInfo.MemberType.TypeCode;
            }
            switch (typeCode)
            {
            case XmlTypeCode.UntypedAtomic:
                return(new UntypedAtomic(nav.Value));

            case XmlTypeCode.Integer:
            case XmlTypeCode.PositiveInteger:
            case XmlTypeCode.NegativeInteger:
            case XmlTypeCode.NonPositiveInteger:
                return((Integer)(decimal)nav.TypedValue);

            case XmlTypeCode.Date:
                return(DateValue.Parse(nav.Value));

            case XmlTypeCode.DateTime:
                return(DateTimeValue.Parse(nav.Value));

            case XmlTypeCode.Time:
                return(TimeValue.Parse(nav.Value));

            case XmlTypeCode.Duration:
                return(DurationValue.Parse(nav.Value));

            case XmlTypeCode.DayTimeDuration:
                return(new DayTimeDurationValue((TimeSpan)nav.TypedValue));

            case XmlTypeCode.YearMonthDuration:
                return(new YearMonthDurationValue((TimeSpan)nav.TypedValue));

            case XmlTypeCode.GDay:
                return(GDayValue.Parse(nav.Value));

            case XmlTypeCode.GMonth:
                return(GMonthValue.Parse(nav.Value));

            case XmlTypeCode.GMonthDay:
                return(GMonthDayValue.Parse(nav.Value));

            case XmlTypeCode.GYear:
                return(GYearValue.Parse(nav.Value));

            case XmlTypeCode.GYearMonth:
                return(GYearMonthValue.Parse(nav.Value));

            case XmlTypeCode.QName:
            case XmlTypeCode.Notation:
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
                ExtFuncs.ScanLocalNamespaces(nsmgr, nav.Clone(), true);
                if (schemaInfo.SchemaType.TypeCode == XmlTypeCode.Notation)
                {
                    return(NotationValue.Parse(nav.Value, nsmgr));
                }
                else
                {
                    return(QNameValue.Parse(nav.Value, nsmgr));
                }
            }

            case XmlTypeCode.AnyUri:
                return(new AnyUriValue(nav.Value));

            case XmlTypeCode.HexBinary:
                return(new HexBinaryValue((byte[])nav.TypedValue));

            case XmlTypeCode.Base64Binary:
                return(new Base64BinaryValue((byte[])nav.TypedValue));

            case XmlTypeCode.Idref:
                if (schemaInfo.SchemaType == SequenceType.XmlSchema.IDREFS)
                {
                    return(new IDREFSValue((string[])nav.TypedValue));
                }
                goto default;

            case XmlTypeCode.NmToken:
                if (schemaInfo.SchemaType == SequenceType.XmlSchema.NMTOKENS)
                {
                    return(new NMTOKENSValue((string[])nav.TypedValue));
                }
                goto default;

            case XmlTypeCode.Entity:
                if (schemaInfo.SchemaType == SequenceType.XmlSchema.ENTITIES)
                {
                    return(new ENTITIESValue((string[])nav.TypedValue));
                }
                goto default;

            default:
                return(nav.TypedValue);
            }
        }
Example #10
0
        public static object ChangeType(XmlSchemaType xmlType, object value, SequenceType type,
                                        XmlNameTable nameTable, XmlNamespaceManager nsmgr)
        {
            if (type.TypeCode == XmlTypeCode.AnyAtomicType || xmlType.TypeCode == type.TypeCode)
            {
                return(value);
            }
            try
            {
                switch (xmlType.TypeCode)
                {
                case XmlTypeCode.String:
                case XmlTypeCode.UntypedAtomic:
                    switch (type.TypeCode)
                    {
                    case XmlTypeCode.UntypedAtomic:
                        return(new UntypedAtomic(value.ToString()));

                    case XmlTypeCode.String:
                        return(value.ToString());

                    case XmlTypeCode.DateTime:
                        return(DateTimeValue.Parse(value.ToString()));

                    case XmlTypeCode.Date:
                        return(DateValue.Parse(value.ToString()));

                    case XmlTypeCode.Time:
                        return(TimeValue.Parse(value.ToString()));

                    case XmlTypeCode.GYearMonth:
                        return(GYearMonthValue.Parse(value.ToString()));

                    case XmlTypeCode.GYear:
                        return(GYearValue.Parse(value.ToString()));

                    case XmlTypeCode.GMonth:
                        return(GMonthValue.Parse(value.ToString()));

                    case XmlTypeCode.GMonthDay:
                        return(GMonthDayValue.Parse(value.ToString()));

                    case XmlTypeCode.GDay:
                        return(GDayValue.Parse(value.ToString()));

                    case XmlTypeCode.Duration:
                        return(DurationValue.Parse(value.ToString()));

                    case XmlTypeCode.QName:
                        if (xmlType.TypeCode == XmlTypeCode.UntypedAtomic)
                        {
                            throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004,
                                                      new SequenceType(xmlType, XmlTypeCardinality.One, null), type);
                        }
                        return(QNameValue.Parse(value.ToString(), nsmgr));

                    case XmlTypeCode.Notation:
                        return(NotationValue.Parse(value.ToString(), nsmgr));

                    case XmlTypeCode.AnyUri:
                        return(new AnyUriValue(value.ToString()));

                    default:
                    {
                        string text = value.ToString();
                        object res  = type.SchemaType.Datatype.ParseValue(text, nameTable, nsmgr);
                        switch (type.TypeCode)
                        {
                        case XmlTypeCode.Integer:
                        case XmlTypeCode.PositiveInteger:
                        case XmlTypeCode.NegativeInteger:
                        case XmlTypeCode.NonPositiveInteger:
                        case XmlTypeCode.NonNegativeInteger:
                            return((Integer)Convert.ToDecimal(res));

                        case XmlTypeCode.DayTimeDuration:
                            return(new DayTimeDurationValue((TimeSpan)res));

                        case XmlTypeCode.YearMonthDuration:
                            return(new YearMonthDurationValue((TimeSpan)res));

                        case XmlTypeCode.HexBinary:
                            return(new HexBinaryValue((byte[])res));

                        case XmlTypeCode.Base64Binary:
                            if (text.EndsWith("==") && (text.Length < 3 || "AQgw".IndexOf(text[text.Length - 3]) == -1))
                            {
                                throw new XPath2Exception("FORG0001", Properties.Resources.FORG0001, value);
                            }
                            return(new Base64BinaryValue((byte[])res));

                        case XmlTypeCode.Idref:
                            if (type.SchemaType == SequenceType.XmlSchema.IDREFS)
                            {
                                return(new IDREFSValue((string[])res));
                            }
                            goto default;

                        case XmlTypeCode.NmToken:
                            if (type.SchemaType == SequenceType.XmlSchema.NMTOKENS)
                            {
                                return(new NMTOKENSValue((string[])res));
                            }
                            goto default;

                        case XmlTypeCode.Entity:
                            if (type.SchemaType == SequenceType.XmlSchema.ENTITIES)
                            {
                                return(new ENTITIESValue((string[])res));
                            }
                            goto default;

                        default:
                            return(res);
                        }
                    }
                    }

                case XmlTypeCode.Boolean:
                    switch (type.TypeCode)
                    {
                    case XmlTypeCode.Decimal:
                    case XmlTypeCode.Float:
                    case XmlTypeCode.Double:
                    case XmlTypeCode.Integer:
                    case XmlTypeCode.NonPositiveInteger:
                    case XmlTypeCode.NegativeInteger:
                    case XmlTypeCode.Long:
                    case XmlTypeCode.Int:
                    case XmlTypeCode.Short:
                    case XmlTypeCode.Byte:
                    case XmlTypeCode.NonNegativeInteger:
                    case XmlTypeCode.UnsignedLong:
                    case XmlTypeCode.UnsignedInt:
                    case XmlTypeCode.UnsignedShort:
                    case XmlTypeCode.UnsignedByte:
                    case XmlTypeCode.PositiveInteger:
                        return(ChangeType(value, type.ItemType));

                    case XmlTypeCode.String:
                        return(XPath2Convert.ToString((bool)value));

                    case XmlTypeCode.UntypedAtomic:
                        return(new UntypedAtomic(XPath2Convert.ToString((bool)value)));
                    }
                    break;

                case XmlTypeCode.Integer:
                case XmlTypeCode.NonPositiveInteger:
                case XmlTypeCode.NegativeInteger:
                case XmlTypeCode.Long:
                case XmlTypeCode.Int:
                case XmlTypeCode.Short:
                case XmlTypeCode.Byte:
                case XmlTypeCode.NonNegativeInteger:
                case XmlTypeCode.UnsignedLong:
                case XmlTypeCode.UnsignedInt:
                case XmlTypeCode.UnsignedShort:
                case XmlTypeCode.UnsignedByte:
                case XmlTypeCode.PositiveInteger:
                case XmlTypeCode.Decimal:
                case XmlTypeCode.Float:
                case XmlTypeCode.Double:
                    switch (type.TypeCode)
                    {
                    case XmlTypeCode.String:
                        return(ToString(value));

                    case XmlTypeCode.UntypedAtomic:
                        return(new UntypedAtomic(ToString(value)));

                    case XmlTypeCode.Boolean:
                        return(CoreFuncs.BooleanValue(value));

                    case XmlTypeCode.AnyUri:
                        throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004,
                                                  new SequenceType(xmlType, XmlTypeCardinality.One, null), type);

                    default:
                        return(ChangeType(value, type.ItemType));
                    }

                default:
                {
                    IXmlConvertable convert = value as IXmlConvertable;
                    if (convert != null)
                    {
                        return(convert.ValueAs(type, nsmgr));
                    }
                    if (type.TypeCode == XmlTypeCode.String)
                    {
                        return(ToString(value));
                    }
                    if (type.TypeCode == XmlTypeCode.UntypedAtomic)
                    {
                        return(new UntypedAtomic(ToString(value)));
                    }
                    return(type.SchemaType.Datatype.ChangeType(value, type.ValueType));
                }
                }
            }
            catch (XmlSchemaException ex)
            {
                throw new XPath2Exception(ex.Message, ex);
            }
            catch (InvalidCastException)
            {
                throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004,
                                          new SequenceType(xmlType, XmlTypeCardinality.One, null), type);
            }
            catch (FormatException)
            {
                throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004,
                                          new SequenceType(xmlType, XmlTypeCardinality.One, null), type);
            }
            throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004,
                                      new SequenceType(xmlType, XmlTypeCardinality.One, null), type);
        }