예제 #1
0
        private void Visit( XmlElement e )
        {
            int name = Schema.GetNameCode( e.NamespaceURI, e.LocalName );
            AttributesSet atts = new AttributesSet();
            atts.Reset(Schema,e);
            CurrentState = CurrentState.StartElement( name, atts, State.emptySet );
            if( CurrentState==State.emptySet )
                throw new DomValidationException( e, "unexpected start element" );

            ValidationContext context = new XmlElementContext(e);

            StringBuilder builder = new StringBuilder();
            foreach( XmlNode n in e.ChildNodes ) {
                if( n is XmlText || n is XmlCDataSection || n is XmlWhitespace) {
                    builder.Append( n.Value );
                    continue;
                }
                if( n is XmlElement ) {
                    ProcessText( builder, context, e, atts );
                    Visit( (XmlElement)n );
                }
            }

            ProcessText( builder, context, e, atts );

            CurrentState = CurrentState.EndElement(atts, State.emptySet );
            if( CurrentState==State.emptySet )
                throw new DomValidationException( e, "unexpected end element" );
        }
예제 #2
0
        private void ProcessText( StringBuilder builder, ValidationContext context, XmlElement e, AttributesSet atts )
        {
            //			if( builder.Length==0 )
            //				return;

            string text = builder.ToString();
            builder.Length = 0;

            CurrentState = CurrentState.Text( text, context, atts, State.emptySet );
            if( CurrentState==State.emptySet )
                throw new DomValidationException( e, "unexpected text" );
        }
예제 #3
0
 /**
 * Expands StateSet by taking applicable attribute transitions.
 */
 public abstract State Expand( AttributesSet attributes, State partialResult );
예제 #4
0
            public override State Text( string value, ValidationContext context,
                AttributesSet attributes, State result)
            {
                State i;

                if( Alphabet.TextToLeft )
                    i = MakeInterleave(
                        Lhs.Text(value,context,attributes,emptySet),
                        Rhs, Alphabet );
                else
                    i = MakeInterleave(
                        Lhs,
                        Rhs.Text(value,context,attributes,emptySet),
                        Alphabet );

                result = MakeChoice( result, i );
                if( i is Interleave && ((Interleave)i).CanJoin )
                    result = Alphabet.Join.Expand( attributes, result );

                return result;
            }
예제 #5
0
 public override State Expand( AttributesSet attributes, State partialResult )
 {
     return MakeChoice( partialResult, MakeInterleave(
         Lhs.Expand(attributes,emptySet),
         Rhs.Expand(attributes,emptySet),
         Alphabet ));
 }
예제 #6
0
 public Interleave( State l, State r, Transition.Interleave a )
 {
     this.Lhs=l;
     this.Rhs=r;
     this.Alphabet=a;
 }
예제 #7
0
 public override State WrapAfterByAfter( State newThen, State partialResult )
 {
     return Rhs.WrapAfterByAfter( newThen,
         Lhs.WrapAfterByAfter( newThen, partialResult ));
 }
예제 #8
0
 public override State StartElement(
     int nameCode, AttributesSet attributes, State partialResult)
 {
     return Rhs.StartElement(nameCode,attributes,
         Lhs.StartElement(nameCode,attributes,partialResult));
 }
예제 #9
0
 public override State EndElement( AttributesSet attributes, State partialResult )
 {
     if( Child.IsFinal )		return Then.Expand(attributes,partialResult);
     else                    return partialResult;
 }
예제 #10
0
            public override bool Contains( State s )
            {
                if(!(s is After)) return false;

                After rhs = (After)s;

                // TODO needs more generalization
                return this.Child.Contains(rhs.Child)
                    && rhs.Then.Contains(this.Then)
                    && this.Then.Contains(rhs.Then);
            }
예제 #11
0
 public After( State c, State t )
 {
     this.Child=c;
     this.Then=t;
 }
예제 #12
0
 public virtual State WrapAfterByInterleaveRight( State rhs, Transition.Interleave alphabet, State partialResult )
 {
     Debug.Fail("can't happen for interleave/single state");
     throw new InvalidOperationException();
 }
예제 #13
0
 public virtual State WrapAfterByAfter( State newThen, State partialResult )
 {
     Debug.Fail("can't happen for interleave/single state");
     throw new InvalidOperationException();
 }
예제 #14
0
 /**
 * Performs a transition by a text chunk.
 */
 public abstract State Text( string value, ValidationContext context,
     AttributesSet attributes, State partialResult);
예제 #15
0
 /// <summary>
 /// Performs a transition by a start element event.
 /// </summary>
 public abstract State StartElement( int nameCode, AttributesSet attributes, State partialResult );
예제 #16
0
 public override State EndElement( AttributesSet attributes, State partialResult )
 {
     return Rhs.EndElement( attributes,
         Lhs.EndElement( attributes, partialResult ));
 }
예제 #17
0
 public override State Expand( AttributesSet attributes, State partialResult )
 {
     return Rhs.Expand( attributes, Lhs.Expand( attributes, partialResult ));
 }
예제 #18
0
 public override State Expand( AttributesSet attributes, State partialResult )
 {
     return MakeChoice( partialResult,
         MakeAfter( Child.Expand(attributes,emptySet), Then ));
     // don't expand the "then" states because it needs different attributes.
     // we'll expand them at the endElement method.
 }
예제 #19
0
 public override State Text( string value, ValidationContext context,
     AttributesSet attributes, State partialResult)
 {
     return Rhs.Text(value,context,attributes,
         Lhs.Text(value,context,attributes,partialResult));
 }
예제 #20
0
 public override State StartElement(
     int nameCode, AttributesSet attributes, State partialResult)
 {
     return Child.StartElement(
         nameCode,attributes,emptySet).WrapAfterByAfter( Then, partialResult );
 }
예제 #21
0
 public override State WrapAfterByInterleaveRight( State newRhs, Transition.Interleave alphabet, State partialResult )
 {
     return Rhs.WrapAfterByInterleaveRight( newRhs, alphabet,
         Lhs.WrapAfterByInterleaveRight( newRhs, alphabet, partialResult ));
 }
예제 #22
0
 public override State Text( string value, ValidationContext context,
     AttributesSet attributes, State partialResult)
 {
     return MakeChoice( partialResult, MakeAfter(
         Child.Text(value,context,attributes,emptySet), Then ));
 }
예제 #23
0
 public override State EndElement( AttributesSet attributes, State partialResult )
 {
     // this method can never be called because
     Debug.Fail("InterleaveState must not appear above AfterState.");
     throw new InvalidOperationException();
 }
예제 #24
0
 public override State WrapAfterByAfter( State newThen, State partialResult )
 {
     return MakeChoice( partialResult,
         MakeAfter( Child, MakeAfter( Then, newThen ) ));
 }
예제 #25
0
            public override State StartElement(
                int nameCode, AttributesSet attributes, State result)
            {
                State l = Lhs.StartElement(nameCode,attributes,emptySet);
                State r = Rhs.StartElement(nameCode,attributes,emptySet);

                result = r.WrapAfterByInterleaveLeft ( Lhs, Alphabet, result );
                result = l.WrapAfterByInterleaveRight( Rhs, Alphabet, result );

                return result;
            }
예제 #26
0
 public override State WrapAfterByInterleaveRight( State rhs, Transition.Interleave alphabet, State partialResult )
 {
     return MakeChoice( partialResult,
         MakeAfter( Child, MakeInterleave( Then, rhs, alphabet ) ) );
 }
예제 #27
0
 /// <summary>
 /// Validates a DOM tree rooted at the specified element.
 /// </summary>
 /// <exception cref="DomValidationException">
 /// If the tree is invalid
 /// </exception>
 public void Validate( XmlElement e )
 {
     CurrentState = Schema.InitialState;
     Visit(e);
 }
예제 #28
0
 public Choice( State l, State r )
 {
     this.Lhs=l;
     this.Rhs=r;
 }
예제 #29
0
 public override bool Contains( State s )
 {
     return Lhs.Contains(s) || Rhs.Contains(s);
 }
예제 #30
0
 /**
 * Performs a transition by an end element event.
 *
 * @param attributes
 *      attributes of the parent element of the element being closed.
 */
 public abstract State EndElement( AttributesSet attributes, State partialResult );