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" ); }
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 StartElement( int nameCode, AttributesSet attributes, State partialResult) { return Child.StartElement( nameCode,attributes,emptySet).WrapAfterByAfter( Then, partialResult ); }
public override State StartElement( int nameCode, AttributesSet attributes, State result) { for( Transition.Element e=eTr; e!=null; e=e.Next ) { if( e.Accepts(nameCode) ) { result = MakeChoice(result, MakeAfter( e.Left.Expand(attributes,emptySet), e.Right)); } } return result; }
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 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 StartElement( int nameCode, AttributesSet attributes, State partialResult) { return Rhs.StartElement(nameCode,attributes, Lhs.StartElement(nameCode,attributes,partialResult)); }
/** * 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 );
public override State Text( string value, ValidationContext context, AttributesSet attributes, State partialResult) { return partialResult; }
public override State StartElement( int nameCode, AttributesSet attributes, State partialResult ) { return partialResult; }
public override State Expand(AttributesSet attributes, State partialResult) { return partialResult; }
public override State EndElement( AttributesSet attributes, State partialResult ) { return partialResult; }
public override State Text( string value, ValidationContext context, AttributesSet attributes, State result) { bool ignorable = (value.Trim().Length==0); if(ignorable) // this text is ignorable result = MakeChoice( result, this ); for( Transition.Data da=dTr; da!=null; da=da.Next ) { // data transition can be taken when it's accepted by the datatype AND // the except expression fails. if( da.Datatype.IsValid(value,context) && !da.Left.Text( value, context, AttributesSet.empty, emptySet ).IsFinal ) result = da.Right.Expand(attributes,result); } for( Transition.Value va=vTr; va!=null; va=va.Next ) { if( va.Accepts(value,context) ) result = va.Right.Expand(attributes,result); } for( Transition.List la=lTr; la!=null; la=la.Next ) { string[] tokens = value.Split(' ','\t','\r','\n'); // a list can't contain interleave, so no need to expand State child = la.Left; foreach( string token in tokens ) { if( token.Length!=0 ) child = child.Text( token, context, AttributesSet.empty, emptySet ); } if( child.IsFinal ) result = la.Right.Expand(attributes,result); } return result; }
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 )); }
/** * 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 partialResult) { return Rhs.Text(value,context,attributes, Lhs.Text(value,context,attributes,partialResult)); }
/// <summary> /// Performs a transition by a start element event. /// </summary> public abstract State StartElement( int nameCode, AttributesSet attributes, State partialResult );
public override State Expand( AttributesSet attributes, State partialResult ) { return MakeChoice( partialResult, MakeInterleave( Lhs.Expand(attributes,emptySet), Rhs.Expand(attributes,emptySet), Alphabet )); }
/** * Performs a transition by a text chunk. */ public abstract State Text( string value, ValidationContext context, 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 EndElement( AttributesSet attributes, State partialResult ) { if( Child.IsFinal ) return Then.Expand(attributes,partialResult); else return 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 Expand( AttributesSet attributes, State result ) { if( result.Contains(this) ) return result; // no need to expand more if( IsPersistent ) result = MakeChoice( result, this ); for( Transition.Att aa = aTr; aa!=null; aa=aa.Next ) { int matchCount=0,failCount=0; for( int j=attributes.Count-1; j>=0; j-- ) { int nameCode = attributes.GetName(j); if( aa.Accepts(nameCode) ) { string value = attributes.GetValue(j); State s = aa.Left; s = s.Text( value, attributes.Context, AttributesSet.empty, emptySet ); if( s.IsFinal ) matchCount++; else failCount++; } } if( (matchCount==1 && failCount==0 && !aa.Repeated) || (matchCount!=0 && failCount==0 && aa.Repeated) ) result = aa.Right.Expand( attributes, result ); } for( Transition.NoAtt nea = nTr; nea!=null; nea=nea.Next ) { int j; for( j=attributes.Count-1; j>=0; j-- ) { int nc = attributes.GetName(j); if( nea.Accepts(nc) ) // this attribute is prohibited. break; } if(j==-1) result = nea.Right.Expand( attributes, result ); } for( Transition.Interleave ia = iTr; ia!=null; ia=ia.Next ) { result = MakeChoice( result, MakeInterleave( ia.Left. Expand( attributes, emptySet ), ia.Right.Expand( attributes, emptySet ), ia )); } return result; }