Esempio n. 1
0
        private ValidatingReaderNodeData AddContent(XmlNodeType nodeType)
        {
            Debug.Assert(_contentIndex <= _contentEvents.Length);
            ValidatingReaderNodeData contentInfo = _contentEvents[_contentIndex];

            if (contentInfo != null)
            {
                contentInfo.Clear(nodeType);
                _contentIndex++;
                return(contentInfo);
            }
            if (_contentIndex >= _contentEvents.Length - 1)
            { //reached capacity of array, Need to increase capacity to twice the initial
                ValidatingReaderNodeData[] newContentEvents = new ValidatingReaderNodeData[_contentEvents.Length * 2];
                Array.Copy(_contentEvents, newContentEvents, _contentEvents.Length);
                _contentEvents = newContentEvents;
            }
            contentInfo = _contentEvents[_contentIndex];
            if (contentInfo == null)
            {
                contentInfo = new ValidatingReaderNodeData(nodeType);
                _contentEvents[_contentIndex] = contentInfo;
            }
            _contentIndex++;
            return(contentInfo);
        }
Esempio n. 2
0
        private ValidatingReaderNodeData AddContent(XmlNodeType nodeType)
        {
            ValidatingReaderNodeData data = this.contentEvents[this.contentIndex];

            if (data != null)
            {
                data.Clear(nodeType);
                this.contentIndex++;
                return(data);
            }
            if (this.contentIndex >= (this.contentEvents.Length - 1))
            {
                ValidatingReaderNodeData[] destinationArray = new ValidatingReaderNodeData[this.contentEvents.Length * 2];
                Array.Copy(this.contentEvents, 0, destinationArray, 0, this.contentEvents.Length);
                this.contentEvents = destinationArray;
            }
            data = this.contentEvents[this.contentIndex];
            if (data == null)
            {
                data = new ValidatingReaderNodeData(nodeType);
                this.contentEvents[this.contentIndex] = data;
            }
            this.contentIndex++;
            return(data);
        }
 // Moves to the attribute with the specified index.
 public override void MoveToAttribute(int i)
 {
     if (i < 0 || i >= attributeCount)
     {
         throw new ArgumentOutOfRangeException("i");
     }
     currentAttrIndex = i;
     cachedNode       = attributeEvents[i];
 }
Esempio n. 4
0
 // Moves to the attribute with the specified index.
 public override void MoveToAttribute(int i)
 {
     if (i < 0 || i >= _attributeCount)
     {
         throw new ArgumentOutOfRangeException(nameof(i));
     }
     _currentAttrIndex = i;
     _cachedNode       = _attributeEvents[i];
 }
Esempio n. 5
0
 public override bool MoveToNextAttribute()
 {
     if ((this.currentAttrIndex + 1) < this.attributeCount)
     {
         this.cachedNode = this.attributeEvents[++this.currentAttrIndex];
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
        internal ValidatingReaderNodeData RecordTextNode(string textValue, string originalStringValue, int depth, int lineNo, int linePos)
        {
            ValidatingReaderNodeData textNode = AddContent(XmlNodeType.Text);

            textNode.SetItemData(textValue, originalStringValue);
            textNode.SetLineInfo(lineNo, linePos);
            textNode.Depth = depth;
            return(textNode);
        }
Esempio n. 7
0
 public override void MoveToAttribute(int i)
 {
     if ((i < 0) || (i >= this.attributeCount))
     {
         throw new ArgumentOutOfRangeException("i");
     }
     this.currentAttrIndex = i;
     this.cachedNode       = this.attributeEvents[i];
 }
Esempio n. 8
0
 // Moves to the next attribute.
 public override bool MoveToNextAttribute()
 {
     if (_currentAttrIndex + 1 < _attributeCount)
     {
         _cachedNode = _attributeEvents[++_currentAttrIndex];
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        internal void SwitchTextNodeAndEndElement(string textValue, string originalStringValue)
        {
            ValidatingReaderNodeData data = this.RecordTextNode(textValue, originalStringValue, this.coreReader.Depth + 1, 0, 0);
            int index = this.contentIndex - 2;
            ValidatingReaderNodeData data2 = this.contentEvents[index];

            this.contentEvents[index] = data;
            this.contentEvents[this.contentIndex - 1] = data2;
        }
Esempio n. 10
0
 public override bool ReadAttributeValue()
 {
     if (this.cachedNode.NodeType != XmlNodeType.Attribute)
     {
         return(false);
     }
     this.cachedNode = this.CreateDummyTextNode(this.cachedNode.RawValue, this.cachedNode.Depth + 1);
     return(true);
 }
Esempio n. 11
0
 // Parses the attribute value into one or more Text and/or EntityReference node types.
 public override bool ReadAttributeValue()
 {
     Debug.Assert(_cacheState == CachingReaderState.Replay);
     if (_cachedNode.NodeType != XmlNodeType.Attribute)
     {
         return(false);
     }
     _cachedNode = CreateDummyTextNode(_cachedNode.RawValue, _cachedNode.Depth + 1);
     return(true);
 }
Esempio n. 12
0
 public override bool MoveToFirstAttribute()
 {
     if (this.attributeCount == 0)
     {
         return(false);
     }
     this.currentAttrIndex = 0;
     this.cachedNode       = this.attributeEvents[0];
     return(true);
 }
Esempio n. 13
0
 private ValidatingReaderNodeData CreateDummyTextNode(string attributeValue, int depth)
 {
     if (_textNode == null)
     {
         _textNode = new ValidatingReaderNodeData(XmlNodeType.Text);
     }
     _textNode.Depth    = depth;
     _textNode.RawValue = attributeValue;
     return(_textNode);
 }
Esempio n. 14
0
 // Moves to the first attribute.
 public override bool MoveToFirstAttribute()
 {
     if (_attributeCount == 0)
     {
         return(false);
     }
     _currentAttrIndex = 0;
     _cachedNode       = _attributeEvents[0];
     return(true);
 }
Esempio n. 15
0
        internal void RecordEndElementNode()
        {
            ValidatingReaderNodeData data = this.AddContent(XmlNodeType.EndElement);

            data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
            data.SetLineInfo(this.coreReader as IXmlLineInfo);
            if (this.coreReader.IsEmptyElement)
            {
                this.readAhead = true;
            }
        }
Esempio n. 16
0
        internal void SwitchTextNodeAndEndElement(string textValue, string originalStringValue)
        {
            Debug.Assert(_coreReader.NodeType == XmlNodeType.EndElement || (_coreReader.NodeType == XmlNodeType.Element && _coreReader.IsEmptyElement));

            ValidatingReaderNodeData textNode = RecordTextNode(textValue, originalStringValue, _coreReader.Depth + 1, 0, 0);
            int endElementIndex = _contentIndex - 2;
            ValidatingReaderNodeData endElementNode = _contentEvents[endElementIndex];

            Debug.Assert(endElementNode.NodeType == XmlNodeType.EndElement);
            _contentEvents[endElementIndex]   = textNode;
            _contentEvents[_contentIndex - 1] = endElementNode;
        }
Esempio n. 17
0
        internal void RecordEndElementNode()
        {
            ValidatingReaderNodeData recordedNode = AddContent(XmlNodeType.EndElement);

            Debug.Assert(_coreReader.NodeType == XmlNodeType.EndElement || (_coreReader.NodeType == XmlNodeType.Element && _coreReader.IsEmptyElement));
            recordedNode.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);
            recordedNode.SetLineInfo(_coreReader as IXmlLineInfo);
            if (_coreReader.IsEmptyElement)
            { //Simulated endElement node for <e/>, the coreReader is on cached Element node itself.
                _readAhead = true;
            }
        }
Esempio n. 18
0
 public override string GetAttribute(string name, string namespaceURI)
 {
     namespaceURI = (namespaceURI == null) ? string.Empty : this.coreReaderNameTable.Get(namespaceURI);
     name         = this.coreReaderNameTable.Get(name);
     for (int i = 0; i < this.attributeCount; i++)
     {
         ValidatingReaderNodeData data = this.attributeEvents[i];
         if (Ref.Equal(data.LocalName, name) && Ref.Equal(data.Namespace, namespaceURI))
         {
             return(data.RawValue);
         }
     }
     return(null);
 }
Esempio n. 19
0
 private int GetAttributeIndexWithPrefix(string name)
 {
     name = this.coreReaderNameTable.Get(name);
     if (name != null)
     {
         for (int i = 0; i < this.attributeCount; i++)
         {
             ValidatingReaderNodeData data = this.attributeEvents[i];
             if (Ref.Equal(data.GetAtomizedNameWPrefix(this.coreReaderNameTable), name))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Esempio n. 20
0
 public override bool MoveToAttribute(string name, string ns)
 {
     ns   = (ns == null) ? string.Empty : this.coreReaderNameTable.Get(ns);
     name = this.coreReaderNameTable.Get(name);
     for (int i = 0; i < this.attributeCount; i++)
     {
         ValidatingReaderNodeData data = this.attributeEvents[i];
         if (Ref.Equal(data.LocalName, name) && Ref.Equal(data.Namespace, ns))
         {
             this.currentAttrIndex = i;
             this.cachedNode       = this.attributeEvents[i];
             return(true);
         }
     }
     return(false);
 }
Esempio n. 21
0
 private int GetAttributeIndexWithoutPrefix(string name)
 {
     name = this.coreReaderNameTable.Get(name);
     if (name != null)
     {
         for (int i = 0; i < this.attributeCount; i++)
         {
             ValidatingReaderNodeData data = this.attributeEvents[i];
             if (Ref.Equal(data.LocalName, name) && (data.Prefix.Length == 0))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Esempio n. 22
0
 private void RecordAttributes()
 {
     this.attributeCount = this.coreReader.AttributeCount;
     if (this.coreReader.MoveToFirstAttribute())
     {
         int attIndex = 0;
         do
         {
             ValidatingReaderNodeData data = this.AddAttribute(attIndex);
             data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
             data.SetLineInfo(this.lineInfo);
             data.RawValue = this.coreReader.Value;
             attIndex++;
         }while (this.coreReader.MoveToNextAttribute());
         this.coreReader.MoveToElement();
     }
 }
 private void Init() {
     coreReaderNameTable = coreReader.NameTable;
     cacheState = CachingReaderState.Init;
     contentIndex = 0;
     currentAttrIndex = -1;
     currentContentIndex = -1;
     attributeCount = 0;
     cachedNode = null;
     readAhead = false;
     //Initialize the cachingReader with start state
     if (coreReader.NodeType == XmlNodeType.Element) {
         ValidatingReaderNodeData element = AddContent(coreReader.NodeType);
         element.SetItemData(coreReader.LocalName, coreReader.Prefix, coreReader.NamespaceURI, coreReader.Depth);  //Only created for element node type
         element.SetLineInfo(lineInfo);
         RecordAttributes();
     }
 }
Esempio n. 24
0
 private void Init()
 {
     this.coreReaderNameTable = this.coreReader.NameTable;
     this.cacheState          = CachingReaderState.Init;
     this.contentIndex        = 0;
     this.currentAttrIndex    = -1;
     this.currentContentIndex = -1;
     this.attributeCount      = 0;
     this.cachedNode          = null;
     this.readAhead           = false;
     if (this.coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData data = this.AddContent(this.coreReader.NodeType);
         data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
         data.SetLineInfo(this.lineInfo);
         this.RecordAttributes();
     }
 }
Esempio n. 25
0
 private void Init()
 {
     _coreReaderNameTable = _coreReader.NameTable;
     _cacheState          = CachingReaderState.Init;
     _contentIndex        = 0;
     _currentAttrIndex    = -1;
     _currentContentIndex = -1;
     _attributeCount      = 0;
     _cachedNode          = null;
     _readAhead           = false;
     //Initialize the cachingReader with start state
     if (_coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData element = AddContent(_coreReader.NodeType);
         element.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);  //Only created for element node type
         element.SetLineInfo(_lineInfo);
         RecordAttributes();
     }
 }
Esempio n. 26
0
        // Moves to the attribute with the specified LocalName and NamespaceURI
        public override bool MoveToAttribute(string name, string ns)
        {
            ns   = (ns == null) ? string.Empty : _coreReaderNameTable.Get(ns);
            name = _coreReaderNameTable.Get(name);
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < _attributeCount; i++)
            {
                attribute = _attributeEvents[i];
                if (Ref.Equal(attribute.LocalName, name) &&
                    Ref.Equal(attribute.Namespace, ns))
                {
                    _currentAttrIndex = i;
                    _cachedNode       = _attributeEvents[i];
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 27
0
        public override bool MoveToAttribute(string name)
        {
            int attributeIndexWithoutPrefix;

            if (name.IndexOf(':') == -1)
            {
                attributeIndexWithoutPrefix = this.GetAttributeIndexWithoutPrefix(name);
            }
            else
            {
                attributeIndexWithoutPrefix = this.GetAttributeIndexWithPrefix(name);
            }
            if (attributeIndexWithoutPrefix >= 0)
            {
                this.currentAttrIndex = attributeIndexWithoutPrefix;
                this.cachedNode       = this.attributeEvents[attributeIndexWithoutPrefix];
                return(true);
            }
            return(false);
        }
 private ValidatingReaderNodeData AddAttribute(int attIndex)
 {
     ValidatingReaderNodeData data = this.attributeEvents[attIndex];
     if (data != null)
     {
         data.Clear(XmlNodeType.Attribute);
         return data;
     }
     if (attIndex >= (this.attributeEvents.Length - 1))
     {
         ValidatingReaderNodeData[] destinationArray = new ValidatingReaderNodeData[this.attributeEvents.Length * 2];
         Array.Copy(this.attributeEvents, 0, destinationArray, 0, this.attributeEvents.Length);
         this.attributeEvents = destinationArray;
     }
     data = this.attributeEvents[attIndex];
     if (data == null)
     {
         data = new ValidatingReaderNodeData(XmlNodeType.Attribute);
         this.attributeEvents[attIndex] = data;
     }
     return data;
 }
Esempio n. 29
0
        private ValidatingReaderNodeData AddAttribute(int attIndex)
        {
            ValidatingReaderNodeData data = this.attributeEvents[attIndex];

            if (data != null)
            {
                data.Clear(XmlNodeType.Attribute);
                return(data);
            }
            if (attIndex >= (this.attributeEvents.Length - 1))
            {
                ValidatingReaderNodeData[] destinationArray = new ValidatingReaderNodeData[this.attributeEvents.Length * 2];
                Array.Copy(this.attributeEvents, 0, destinationArray, 0, this.attributeEvents.Length);
                this.attributeEvents = destinationArray;
            }
            data = this.attributeEvents[attIndex];
            if (data == null)
            {
                data = new ValidatingReaderNodeData(XmlNodeType.Attribute);
                this.attributeEvents[attIndex] = data;
            }
            return(data);
        }
        // Moves to the attribute with the specified Name.
        public override bool MoveToAttribute(string name)
        {
            int i;

            if (name.IndexOf(':') == -1)
            {
                i = GetAttributeIndexWithoutPrefix(name);
            }
            else
            {
                i = GetAttributeIndexWithPrefix(name);
            }

            if (i >= 0)
            {
                currentAttrIndex = i;
                cachedNode       = attributeEvents[i];
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 31
0
        private ValidatingReaderNodeData AddAttribute(int attIndex)
        {
            Debug.Assert(attIndex <= _attributeEvents.Length);
            ValidatingReaderNodeData attInfo = _attributeEvents[attIndex];

            if (attInfo != null)
            {
                attInfo.Clear(XmlNodeType.Attribute);
                return(attInfo);
            }
            if (attIndex >= _attributeEvents.Length - 1)
            { //reached capacity of array, Need to increase capacity to twice the initial
                ValidatingReaderNodeData[] newAttributeEvents = new ValidatingReaderNodeData[_attributeEvents.Length * 2];
                Array.Copy(_attributeEvents, newAttributeEvents, _attributeEvents.Length);
                _attributeEvents = newAttributeEvents;
            }
            attInfo = _attributeEvents[attIndex];
            if (attInfo == null)
            {
                attInfo = new ValidatingReaderNodeData(XmlNodeType.Attribute);
                _attributeEvents[attIndex] = attInfo;
            }
            return(attInfo);
        }
 private ValidatingReaderNodeData AddContent(XmlNodeType nodeType)
 {
     ValidatingReaderNodeData data = this.contentEvents[this.contentIndex];
     if (data != null)
     {
         data.Clear(nodeType);
         this.contentIndex++;
         return data;
     }
     if (this.contentIndex >= (this.contentEvents.Length - 1))
     {
         ValidatingReaderNodeData[] destinationArray = new ValidatingReaderNodeData[this.contentEvents.Length * 2];
         Array.Copy(this.contentEvents, 0, destinationArray, 0, this.contentEvents.Length);
         this.contentEvents = destinationArray;
     }
     data = this.contentEvents[this.contentIndex];
     if (data == null)
     {
         data = new ValidatingReaderNodeData(nodeType);
         this.contentEvents[this.contentIndex] = data;
     }
     this.contentIndex++;
     return data;
 }
Esempio n. 33
0
        // Moves to the attribute with the specified Name.
        public override bool MoveToAttribute(string name)
        {
            int i;

            if (!name.Contains(':'))
            {
                i = GetAttributeIndexWithoutPrefix(name);
            }
            else
            {
                i = GetAttributeIndexWithPrefix(name);
            }

            if (i >= 0)
            {
                _currentAttrIndex = i;
                _cachedNode       = _attributeEvents[i];
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 34
0
 // Moves to the next attribute.
 public override bool MoveToNextAttribute()
 {
     if (_currentAttrIndex + 1 < _coreReaderAttributeCount)
     {
         bool moveTo = _coreReader.MoveToNextAttribute();
         Debug.Assert(moveTo);
         _currentAttrIndex++;
         if (_inlineSchemaParser == null)
         {
             _attributePSVI = _attributePSVINodes[_currentAttrIndex];
         }
         else
         {
             _attributePSVI = null;
         }
         _validationState = ValidatingReaderState.OnAttribute;
         goto Found;
     }
     else if (_currentAttrIndex + 1 < _attributeCount)
     { //default attribute
         int defaultIndex = ++_currentAttrIndex - _coreReaderAttributeCount;
         _cachedNode = (ValidatingReaderNodeData)_defaultAttributes[defaultIndex];
         _attributePSVI = _cachedNode.AttInfo;
         _validationState = ValidatingReaderState.OnDefaultAttribute;
         goto Found;
     }
     return false;
 Found:
     if (_validationState == ValidatingReaderState.OnReadBinaryContent)
     {
         _readBinaryHelper.Finish();
         _validationState = _savedState;
     }
     return true;
 }
 public override void MoveToAttribute(int i)
 {
     if ((i < 0) || (i >= this.attributeCount))
     {
         throw new ArgumentOutOfRangeException("i");
     }
     this.currentAttrIndex = i;
     this.cachedNode = this.attributeEvents[i];
 }
 // Moves to the next attribute.
 public override bool MoveToNextAttribute() {
     if (currentAttrIndex + 1 < coreReaderAttributeCount) {
         bool moveTo = coreReader.MoveToNextAttribute();
         Debug.Assert(moveTo);
         currentAttrIndex++;
         if (inlineSchemaParser == null) {
             attributePSVI = attributePSVINodes[currentAttrIndex];
         }
         else {
             attributePSVI = null;
         }
         validationState = ValidatingReaderState.OnAttribute;
         goto Found;
     }
     else if (currentAttrIndex + 1 < attributeCount) { //default attribute
         int defaultIndex = ++currentAttrIndex - coreReaderAttributeCount;
         cachedNode = (ValidatingReaderNodeData)defaultAttributes[defaultIndex];
         attributePSVI = cachedNode.AttInfo;
         validationState = ValidatingReaderState.OnDefaultAttribute;
         goto Found;
     }
     return false;
 Found:
     if (validationState == ValidatingReaderState.OnReadBinaryContent) {
         readBinaryHelper.Finish();
         validationState = savedState;
     }
     return true;
 }
 // Moves to the first attribute.
 public override bool MoveToFirstAttribute() {
     if (attributeCount == 0) {
         return false;
     }
     currentAttrIndex = 0;
     cachedNode = attributeEvents[0];
     return true;
 }
 // Moves to the attribute with the specified LocalName and NamespaceURI
 public override bool MoveToAttribute( string name, string ns ) {
     ns = (ns == null) ? string.Empty : coreReaderNameTable.Get(ns);
     name = coreReaderNameTable.Get(name);
     ValidatingReaderNodeData attribute;
     for ( int i = 0; i < attributeCount; i++ ) {
         attribute = attributeEvents[i];
         if ( Ref.Equal(attribute.LocalName, name) &&
              Ref.Equal(attribute.Namespace, ns) ) {
                  currentAttrIndex = i;
                  cachedNode = attributeEvents[i];
             return true;
         }
     }
     return false;
 }
        internal void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData) {
            currentState = ValidatorState.Attribute;
            SchemaElementDecl currentElementDecl = context.ElementDecl;

            if (currentElementDecl != null && currentElementDecl.HasDefaultAttribute) {
                for (int i = 0; i < currentElementDecl.DefaultAttDefs.Count; ++i) {
                    SchemaAttDef attdef = (SchemaAttDef)currentElementDecl.DefaultAttDefs[i];
                    if (!attPresence.Contains(attdef.Name)) {
                        if (attdef.DefaultValueTyped == null) { //Invalid attribute default in the schema
                            continue;
                        }

                        //Check to see default attributes WILL be qualified if attributeFormDefault = qualified in schema
                        string attributeNS = nameTable.Add(attdef.Name.Namespace);
                        string defaultPrefix = string.Empty;
                        if (attributeNS.Length > 0) {
                            defaultPrefix = GetDefaultAttributePrefix(attributeNS);
                            if (defaultPrefix == null || defaultPrefix.Length == 0) {
                                SendValidationEvent(Res.Sch_DefaultAttributeNotApplied, new string[2] { attdef.Name.ToString(), QNameString(context.LocalName, context.Namespace)});
                                continue;
                            }
                        }
                        XmlSchemaDatatype datatype = attdef.Datatype;
                        if (createNodeData) {
                            ValidatingReaderNodeData attrData = new ValidatingReaderNodeData();
                            attrData.LocalName = nameTable.Add(attdef.Name.Name);
                            attrData.Namespace = attributeNS;
                            attrData.Prefix = nameTable.Add(defaultPrefix);
                            attrData.NodeType = XmlNodeType.Attribute;

                            //set PSVI properties
                            AttributePSVIInfo attrValidInfo = new AttributePSVIInfo();
                            XmlSchemaInfo attSchemaInfo = attrValidInfo.attributeSchemaInfo;
                            Debug.Assert(attSchemaInfo != null);
                            if (attdef.Datatype.Variety == XmlSchemaDatatypeVariety.Union) {
                                XsdSimpleValue simpleValue = attdef.DefaultValueTyped as XsdSimpleValue;
                                attSchemaInfo.MemberType = simpleValue.XmlType;
                                datatype = simpleValue.XmlType.Datatype;
                                attrValidInfo.typedAttributeValue = simpleValue.TypedValue;
                            }
                            else {
                                attrValidInfo.typedAttributeValue = attdef.DefaultValueTyped;
                            }
                            attSchemaInfo.IsDefault = true;
                            attSchemaInfo.Validity = XmlSchemaValidity.Valid;
                            attSchemaInfo.SchemaType = attdef.SchemaType;
                            attSchemaInfo.SchemaAttribute = attdef.SchemaAttribute;
                            attrData.RawValue = attSchemaInfo.XmlType.ValueConverter.ToString(attrValidInfo.typedAttributeValue);

                            attrData.AttInfo = attrValidInfo;
                            defaultAttributes.Add(attrData);
                        }
                        else {
                            defaultAttributes.Add(attdef.SchemaAttribute);
                        }
                        CheckTokenizedTypes(datatype, attdef.DefaultValueTyped, true);
                        if (HasIdentityConstraints) {
                            AttributeIdentityConstraints(attdef.Name.Name, attdef.Name.Namespace, attdef.DefaultValueTyped, attdef.DefaultValueRaw, datatype);
                        }
                    }
                }
            }
            return;
        }
        // Reads the next node from the stream/TextReader.
        public override bool Read() {
            switch (cacheState) {
                case CachingReaderState.Init:
                    cacheState = CachingReaderState.Record;
                    goto case CachingReaderState.Record;

                case CachingReaderState.Record: 
                    ValidatingReaderNodeData recordedNode = null;
                    if (coreReader.Read()) {
                        switch(coreReader.NodeType) {
                            case XmlNodeType.Element:
                                //Dont record element within the content of a union type since the main reader will break on this and the underlying coreReader will be positioned on this node
                                cacheState = CachingReaderState.ReaderClosed;
                                return false;

                            case XmlNodeType.EndElement:
                                recordedNode = AddContent(coreReader.NodeType);
                                recordedNode.SetItemData(coreReader.LocalName, coreReader.Prefix, coreReader.NamespaceURI, coreReader.Depth);  //Only created for element node type
                                recordedNode.SetLineInfo(lineInfo);
                                break;

                            case XmlNodeType.Comment:
                            case XmlNodeType.ProcessingInstruction:
                            case XmlNodeType.Text:
                            case XmlNodeType.Whitespace:
                            case XmlNodeType.SignificantWhitespace:
                                recordedNode = AddContent(coreReader.NodeType);
                                recordedNode.SetItemData(coreReader.Value);
                                recordedNode.SetLineInfo(lineInfo);
                                recordedNode.Depth = coreReader.Depth;
                                break;

                            default:
                                break;       
                        }
                        cachedNode = recordedNode;
                        return true;    
                    }
                    else {
                        cacheState = CachingReaderState.ReaderClosed;
                        return false;
                    }    

                case CachingReaderState.Replay:
                    if (currentContentIndex >= contentIndex) { //When positioned on the last cached node, switch back as the underlying coreReader is still positioned on this node
                        cacheState = CachingReaderState.ReaderClosed;
                        cacheHandler(this);
                        if (coreReader.NodeType != XmlNodeType.Element || readAhead) { //Only when coreReader not positioned on Element node, read ahead, otherwise it is on the next element node already, since this was not cached
                            return coreReader.Read();
                        }
                        return true;                        
                    }
                    cachedNode = contentEvents[currentContentIndex];
                    if (currentContentIndex > 0) {
                        ClearAttributesInfo();
                    }
                    currentContentIndex++;
                    return true;

                default:
                    return false;
            }
        }
 internal void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData)
 {
     this.currentState = ValidatorState.Attribute;
     SchemaElementDecl elementDecl = this.context.ElementDecl;
     if ((elementDecl != null) && elementDecl.HasDefaultAttribute)
     {
         for (int i = 0; i < elementDecl.DefaultAttDefs.Count; i++)
         {
             SchemaAttDef def = (SchemaAttDef) elementDecl.DefaultAttDefs[i];
             if (!this.attPresence.Contains(def.Name) && (def.DefaultValueTyped != null))
             {
                 string attributeNS = this.nameTable.Add(def.Name.Namespace);
                 string array = string.Empty;
                 if (attributeNS.Length > 0)
                 {
                     array = this.GetDefaultAttributePrefix(attributeNS);
                     if ((array == null) || (array.Length == 0))
                     {
                         this.SendValidationEvent("Sch_DefaultAttributeNotApplied", new string[] { def.Name.ToString(), QNameString(this.context.LocalName, this.context.Namespace) });
                         continue;
                     }
                 }
                 XmlSchemaDatatype dtype = def.Datatype;
                 if (createNodeData)
                 {
                     ValidatingReaderNodeData data = new ValidatingReaderNodeData {
                         LocalName = this.nameTable.Add(def.Name.Name),
                         Namespace = attributeNS,
                         Prefix = this.nameTable.Add(array),
                         NodeType = XmlNodeType.Attribute
                     };
                     AttributePSVIInfo info = new AttributePSVIInfo();
                     XmlSchemaInfo attributeSchemaInfo = info.attributeSchemaInfo;
                     if (def.Datatype.Variety == XmlSchemaDatatypeVariety.Union)
                     {
                         XsdSimpleValue defaultValueTyped = def.DefaultValueTyped as XsdSimpleValue;
                         attributeSchemaInfo.MemberType = defaultValueTyped.XmlType;
                         dtype = defaultValueTyped.XmlType.Datatype;
                         info.typedAttributeValue = defaultValueTyped.TypedValue;
                     }
                     else
                     {
                         info.typedAttributeValue = def.DefaultValueTyped;
                     }
                     attributeSchemaInfo.IsDefault = true;
                     attributeSchemaInfo.Validity = XmlSchemaValidity.Valid;
                     attributeSchemaInfo.SchemaType = def.SchemaType;
                     attributeSchemaInfo.SchemaAttribute = def.SchemaAttribute;
                     data.RawValue = attributeSchemaInfo.XmlType.ValueConverter.ToString(info.typedAttributeValue);
                     data.AttInfo = info;
                     defaultAttributes.Add(data);
                 }
                 else
                 {
                     defaultAttributes.Add(def.SchemaAttribute);
                 }
                 this.CheckTokenizedTypes(dtype, def.DefaultValueTyped, true);
                 if (this.HasIdentityConstraints)
                 {
                     this.AttributeIdentityConstraints(def.Name.Name, def.Name.Namespace, def.DefaultValueTyped, def.DefaultValueRaw, dtype);
                 }
             }
         }
     }
 }
 // Moves to the attribute with the specified index
 public override void MoveToAttribute(int i) {
     if (i < 0 || i >= attributeCount) {
         throw new ArgumentOutOfRangeException("i");
     }
     currentAttrIndex = i;
     if (i < coreReaderAttributeCount) { //reader attribute
         coreReader.MoveToAttribute(i);
         if (inlineSchemaParser == null) {
             attributePSVI = attributePSVINodes[i];
         }
         else {
             attributePSVI = null;
         }
         validationState = ValidatingReaderState.OnAttribute;
     }
     else { //default attribute
         int defaultIndex = i - coreReaderAttributeCount;
         cachedNode = (ValidatingReaderNodeData)defaultAttributes[defaultIndex];
         attributePSVI = cachedNode.AttInfo;
         validationState = ValidatingReaderState.OnDefaultAttribute;
     }
     if (validationState == ValidatingReaderState.OnReadBinaryContent) {
         readBinaryHelper.Finish();
         validationState = savedState;
     }
 }
 // Moves to the attribute with the specified LocalName and NamespaceURI
 public override bool MoveToAttribute(string name, string ns) {
     //Check atomized local name and ns
     name = coreReaderNameTable.Get(name);
     ns = ns != null ? coreReaderNameTable.Get(ns) : string.Empty;
     if (name == null || ns == null) { //Name or ns not found in the nameTable, then attribute is not found
         return false;
     }
     if (coreReader.MoveToAttribute(name, ns)) {
         validationState = ValidatingReaderState.OnAttribute;
         if (inlineSchemaParser == null) {
             attributePSVI = GetAttributePSVI(name, ns);
             Debug.Assert(attributePSVI != null);
         }
         else { //Parsing inline schema, no PSVI for schema attributes
             attributePSVI = null;
         }
         goto Found;
     }
     else { //Default attribute
         ValidatingReaderNodeData defaultNode = GetDefaultAttribute(name, ns, true);
         if (defaultNode != null) {
             attributePSVI = defaultNode.AttInfo;
             cachedNode = defaultNode;
             validationState = ValidatingReaderState.OnDefaultAttribute;
             goto Found;
         }
     }
     return false;
 Found:
     if (validationState == ValidatingReaderState.OnReadBinaryContent) {
         readBinaryHelper.Finish();
         validationState = savedState;
     }
     return true;
 }
        // Moves to the attribute with the specified Name
        public override bool MoveToAttribute(string name) {

            if (coreReader.MoveToAttribute(name)) {
                validationState = ValidatingReaderState.OnAttribute;
                attributePSVI = GetAttributePSVI(name);
                goto Found;
            }
            else if (attributeCount > 0) { //Default attribute
                ValidatingReaderNodeData defaultNode = GetDefaultAttribute(name, true);
                if (defaultNode != null) {
                    validationState = ValidatingReaderState.OnDefaultAttribute;
                    attributePSVI = defaultNode.AttInfo;
                    cachedNode = defaultNode;
                    goto Found;
                }
            }
            return false;
        Found:
            if (validationState == ValidatingReaderState.OnReadBinaryContent) {
                readBinaryHelper.Finish();
                validationState = savedState;
            }
            return true;
        }
 // Parses the attribute value into one or more Text and/or EntityReference node types.
 public override bool ReadAttributeValue() {
     if (validationState == ValidatingReaderState.OnReadBinaryContent) {
         readBinaryHelper.Finish();
         validationState = savedState;
     }
     if (NodeType == XmlNodeType.Attribute) {
         if (validationState == ValidatingReaderState.OnDefaultAttribute) {
             cachedNode = CreateDummyTextNode(cachedNode.RawValue, cachedNode.Depth + 1);
             validationState = ValidatingReaderState.OnReadAttributeValue;
             return true;
         }
         return coreReader.ReadAttributeValue();
     }
     return false;
 }
Esempio n. 46
0
 // Moves to the first attribute.
 public override bool MoveToFirstAttribute()
 {
     if (_coreReader.MoveToFirstAttribute())
     {
         _currentAttrIndex = 0;
         if (_inlineSchemaParser == null)
         {
             _attributePSVI = _attributePSVINodes[0];
         }
         else
         {
             _attributePSVI = null;
         }
         _validationState = ValidatingReaderState.OnAttribute;
         goto Found;
     }
     else if (_defaultAttributes.Count > 0)
     { //check for default
         _cachedNode = (ValidatingReaderNodeData)_defaultAttributes[0];
         _attributePSVI = _cachedNode.AttInfo;
         _currentAttrIndex = 0;
         _validationState = ValidatingReaderState.OnDefaultAttribute;
         goto Found;
     }
     return false;
 Found:
     if (_validationState == ValidatingReaderState.OnReadBinaryContent)
     {
         _readBinaryHelper.Finish();
         _validationState = _savedState;
     }
     return true;
 }
Esempio n. 47
0
 // Moves to the attribute with the specified index
 public override void MoveToAttribute(int i)
 {
     if (i < 0 || i >= _attributeCount)
     {
         throw new ArgumentOutOfRangeException(nameof(i));
     }
     _currentAttrIndex = i;
     if (i < _coreReaderAttributeCount)
     { //reader attribute
         _coreReader.MoveToAttribute(i);
         if (_inlineSchemaParser == null)
         {
             _attributePSVI = _attributePSVINodes[i];
         }
         else
         {
             _attributePSVI = null;
         }
         _validationState = ValidatingReaderState.OnAttribute;
     }
     else
     { //default attribute
         int defaultIndex = i - _coreReaderAttributeCount;
         _cachedNode = (ValidatingReaderNodeData)_defaultAttributes[defaultIndex];
         _attributePSVI = _cachedNode.AttInfo;
         _validationState = ValidatingReaderState.OnDefaultAttribute;
     }
     if (_validationState == ValidatingReaderState.OnReadBinaryContent)
     {
         _readBinaryHelper.Finish();
         _validationState = _savedState;
     }
 }
 private ValidatingReaderNodeData AddAttribute(int attIndex) {
     Debug.Assert(attIndex <= attributeEvents.Length);
     ValidatingReaderNodeData attInfo = attributeEvents[attIndex];
     if (attInfo != null) {
         attInfo.Clear(XmlNodeType.Attribute);
         return attInfo;
     }
     if (attIndex >= attributeEvents.Length -1 ) { //reached capacity of array, Need to increase capacity to twice the initial
         ValidatingReaderNodeData[] newAttributeEvents = new ValidatingReaderNodeData[attributeEvents.Length * 2];
         Array.Copy(attributeEvents, 0, newAttributeEvents, 0, attributeEvents.Length);
         attributeEvents = newAttributeEvents;
     }
     attInfo = attributeEvents[attIndex];
     if (attInfo == null) {
         attInfo = new ValidatingReaderNodeData(XmlNodeType.Attribute);
         attributeEvents[attIndex] = attInfo;
     }
     return attInfo;
 }
        // Moves to the attribute with the specified Name.
        public override bool MoveToAttribute( string name ) {
            int i;
            if (name.IndexOf( ':' ) == -1) {
                i = GetAttributeIndexWithoutPrefix( name );
            }
            else {
                i = GetAttributeIndexWithPrefix( name );
            }

            if ( i >= 0 ) {
                currentAttrIndex = i;
                cachedNode = attributeEvents[i];
                return true;
            }
            else {
                return false;
            }
        }
 private ValidatingReaderNodeData CreateDummyTextNode(string attributeValue, int depth) {
     if (textNode == null) {
         textNode = new ValidatingReaderNodeData(XmlNodeType.Text);
     }
     textNode.Depth = depth;
     textNode.RawValue = attributeValue;
     return textNode;
 }
 // Moves to the attribute with the specified index.
 public override void MoveToAttribute(int i) {
     if ( i < 0 || i >= attributeCount ) {
         throw new ArgumentOutOfRangeException( "i" );
     }
     currentAttrIndex = i;
     cachedNode = attributeEvents[i];
 }
 public override bool MoveToAttribute(string name)
 {
     int attributeIndexWithoutPrefix;
     if (name.IndexOf(':') == -1)
     {
         attributeIndexWithoutPrefix = this.GetAttributeIndexWithoutPrefix(name);
     }
     else
     {
         attributeIndexWithoutPrefix = this.GetAttributeIndexWithPrefix(name);
     }
     if (attributeIndexWithoutPrefix >= 0)
     {
         this.currentAttrIndex = attributeIndexWithoutPrefix;
         this.cachedNode = this.attributeEvents[attributeIndexWithoutPrefix];
         return true;
     }
     return false;
 }
 // Moves to the next attribute.
 public override bool MoveToNextAttribute() {
     if (currentAttrIndex + 1 < attributeCount) {
         cachedNode = attributeEvents[++currentAttrIndex];
         return true;
     }
     return false;
 }
 public override bool ReadAttributeValue()
 {
     if (this.cachedNode.NodeType != XmlNodeType.Attribute)
     {
         return false;
     }
     this.cachedNode = this.CreateDummyTextNode(this.cachedNode.RawValue, this.cachedNode.Depth + 1);
     return true;
 }
 // Parses the attribute value into one or more Text and/or EntityReference node types.
 public override bool ReadAttributeValue() {
     Debug.Assert(cacheState == CachingReaderState.Replay);
     if (cachedNode.NodeType != XmlNodeType.Attribute) {
         return false;
     }
     cachedNode = CreateDummyTextNode(cachedNode.RawValue, cachedNode.Depth + 1);
     return true;
 }
        public override bool Read()
        {
            switch (this.cacheState)
            {
                case CachingReaderState.Init:
                    this.cacheState = CachingReaderState.Record;
                    break;

                case CachingReaderState.Record:
                    break;

                case CachingReaderState.Replay:
                    if (this.currentContentIndex < this.contentIndex)
                    {
                        this.cachedNode = this.contentEvents[this.currentContentIndex];
                        if (this.currentContentIndex > 0)
                        {
                            this.ClearAttributesInfo();
                        }
                        this.currentContentIndex++;
                        return true;
                    }
                    this.cacheState = CachingReaderState.ReaderClosed;
                    this.cacheHandler(this);
                    return (((this.coreReader.NodeType == XmlNodeType.Element) && !this.readAhead) || this.coreReader.Read());

                default:
                    return false;
            }
            ValidatingReaderNodeData data = null;
            if (!this.coreReader.Read())
            {
                this.cacheState = CachingReaderState.ReaderClosed;
                return false;
            }
            switch (this.coreReader.NodeType)
            {
                case XmlNodeType.Element:
                    this.cacheState = CachingReaderState.ReaderClosed;
                    return false;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Comment:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    data = this.AddContent(this.coreReader.NodeType);
                    data.SetItemData(this.coreReader.Value);
                    data.SetLineInfo(this.lineInfo);
                    data.Depth = this.coreReader.Depth;
                    break;

                case XmlNodeType.EndElement:
                    data = this.AddContent(this.coreReader.NodeType);
                    data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
                    data.SetLineInfo(this.lineInfo);
                    break;
            }
            this.cachedNode = data;
            return true;
        }
 private ValidatingReaderNodeData AddContent(XmlNodeType nodeType) {
     Debug.Assert(contentIndex <= contentEvents.Length);
     ValidatingReaderNodeData contentInfo = contentEvents[contentIndex];
     if (contentInfo != null) {
         contentInfo.Clear(nodeType);
         contentIndex++;
         return contentInfo;
     }
     if (contentIndex >= contentEvents.Length -1 ) { //reached capacity of array, Need to increase capacity to twice the initial
         ValidatingReaderNodeData[] newContentEvents = new ValidatingReaderNodeData[contentEvents.Length * 2];
         Array.Copy(contentEvents, 0, newContentEvents, 0, contentEvents.Length);
         contentEvents = newContentEvents;
     }
     contentInfo = contentEvents[contentIndex];
     if (contentInfo == null) {
         contentInfo = new ValidatingReaderNodeData(nodeType);
         contentEvents[contentIndex] = contentInfo;
     }
     contentIndex++;
     return contentInfo;
 }
 public override bool MoveToNextAttribute()
 {
     if ((this.currentAttrIndex + 1) < this.attributeCount)
     {
         this.cachedNode = this.attributeEvents[++this.currentAttrIndex];
         return true;
     }
     return false;
 }
 // Moves to the first attribute.
 public override bool MoveToFirstAttribute() {
     if (coreReader.MoveToFirstAttribute()) {
         currentAttrIndex = 0;
         if (inlineSchemaParser == null) {
             attributePSVI = attributePSVINodes[0];
         }
         else {
             attributePSVI = null;
         }
         validationState = ValidatingReaderState.OnAttribute;
         goto Found;
     }
     else if (defaultAttributes.Count > 0) { //check for default
         cachedNode = (ValidatingReaderNodeData)defaultAttributes[0];
         attributePSVI = cachedNode.AttInfo;
         currentAttrIndex = 0;
         validationState = ValidatingReaderState.OnDefaultAttribute;
         goto Found;
     }
     return false;
 Found:
     if (validationState == ValidatingReaderState.OnReadBinaryContent) {
         readBinaryHelper.Finish();
         validationState = savedState;
     }
     return true;
 }
 public override bool MoveToAttribute(string name, string ns)
 {
     ns = (ns == null) ? string.Empty : this.coreReaderNameTable.Get(ns);
     name = this.coreReaderNameTable.Get(name);
     for (int i = 0; i < this.attributeCount; i++)
     {
         ValidatingReaderNodeData data = this.attributeEvents[i];
         if (Ref.Equal(data.LocalName, name) && Ref.Equal(data.Namespace, ns))
         {
             this.currentAttrIndex = i;
             this.cachedNode = this.attributeEvents[i];
             return true;
         }
     }
     return false;
 }