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" ); }
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" ); }
/** * Expands StateSet by taking applicable attribute transitions. */ public abstract State Expand( AttributesSet attributes, State partialResult );
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; }
public override State Expand( AttributesSet attributes, State partialResult ) { return MakeChoice( partialResult, MakeInterleave( Lhs.Expand(attributes,emptySet), Rhs.Expand(attributes,emptySet), Alphabet )); }
public Interleave( State l, State r, Transition.Interleave a ) { this.Lhs=l; this.Rhs=r; this.Alphabet=a; }
public override State WrapAfterByAfter( State newThen, State partialResult ) { return Rhs.WrapAfterByAfter( newThen, Lhs.WrapAfterByAfter( newThen, partialResult )); }
public override State StartElement( int nameCode, AttributesSet attributes, State partialResult) { return Rhs.StartElement(nameCode,attributes, Lhs.StartElement(nameCode,attributes,partialResult)); }
public override State EndElement( AttributesSet attributes, State partialResult ) { if( Child.IsFinal ) return Then.Expand(attributes,partialResult); else return partialResult; }
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); }
public After( State c, State t ) { this.Child=c; this.Then=t; }
public virtual State WrapAfterByInterleaveRight( State rhs, Transition.Interleave alphabet, State partialResult ) { Debug.Fail("can't happen for interleave/single state"); throw new InvalidOperationException(); }
public virtual State WrapAfterByAfter( State newThen, State partialResult ) { Debug.Fail("can't happen for interleave/single state"); throw new InvalidOperationException(); }
/** * Performs a transition by a text chunk. */ public abstract State Text( string value, ValidationContext context, AttributesSet attributes, State partialResult);
/// <summary> /// Performs a transition by a start element event. /// </summary> public abstract State StartElement( int nameCode, AttributesSet attributes, State partialResult );
public override State EndElement( AttributesSet attributes, State partialResult ) { return Rhs.EndElement( attributes, Lhs.EndElement( attributes, partialResult )); }
public override State Expand( AttributesSet attributes, State partialResult ) { return Rhs.Expand( attributes, Lhs.Expand( attributes, partialResult )); }
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. }
public override State Text( string value, ValidationContext context, AttributesSet attributes, State partialResult) { return Rhs.Text(value,context,attributes, Lhs.Text(value,context,attributes,partialResult)); }
public override State StartElement( int nameCode, AttributesSet attributes, State partialResult) { return Child.StartElement( nameCode,attributes,emptySet).WrapAfterByAfter( Then, partialResult ); }
public override State WrapAfterByInterleaveRight( State newRhs, Transition.Interleave alphabet, State partialResult ) { return Rhs.WrapAfterByInterleaveRight( newRhs, alphabet, Lhs.WrapAfterByInterleaveRight( newRhs, alphabet, partialResult )); }
public override State Text( string value, ValidationContext context, AttributesSet attributes, State partialResult) { return MakeChoice( partialResult, MakeAfter( Child.Text(value,context,attributes,emptySet), Then )); }
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(); }
public override State WrapAfterByAfter( State newThen, State partialResult ) { return MakeChoice( partialResult, MakeAfter( Child, MakeAfter( Then, newThen ) )); }
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; }
public override State WrapAfterByInterleaveRight( State rhs, Transition.Interleave alphabet, State partialResult ) { return MakeChoice( partialResult, MakeAfter( Child, MakeInterleave( Then, rhs, alphabet ) ) ); }
/// <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); }
public Choice( State l, State r ) { this.Lhs=l; this.Rhs=r; }
public override bool Contains( State s ) { return Lhs.Contains(s) || Rhs.Contains(s); }
/** * 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 );