public static XmlnsSchemaPointerPart ParseSchemaData(XPointerLexer lexer) { //[1] XmlnsSchemeData ::= NCName S? '=' S? EscapedNamespaceName //[2] EscapedNamespaceName ::= EscapedData* //Read prefix as NCName lexer.NextLexeme(); if (lexer.Kind != XPointerLexer.LexKind.NCName) { Debug.WriteLine(Properties.Resources.InvalidTokenInXmlnsSchemeWhileNCNameExpected); return null; } string prefix = lexer.NCName; lexer.SkipWhiteSpace(); lexer.NextLexeme(); if (lexer.Kind != XPointerLexer.LexKind.Eq) { Debug.WriteLine(Properties.Resources.InvalidTokenInXmlnsSchemeWhileEqualsSignExpected); return null; } lexer.SkipWhiteSpace(); string nsURI; try { nsURI = lexer.ParseEscapedData(); } catch (Exception e) { throw new XPointerSyntaxException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.SyntaxErrorInXmlnsSchemeData, e.Message)); } return new XmlnsSchemaPointerPart(prefix, nsURI); }
/// <summary> /// Parses element() based pointer part and builds instance of <c>ElementSchemaPointerPart</c> class. /// </summary> /// <param name="lexer">Lexical analizer.</param> /// <returns>Newly created <c>ElementSchemaPointerPart</c> object.</returns> public static ElementSchemaPointerPart ParseSchemaData(XPointerLexer lexer) { //Productions: //[1] ElementSchemeData ::= (NCName ChildSequence?) | ChildSequence //[2] ChildSequence ::= ('/' [1-9] [0-9]*)+ StringBuilder xpathBuilder = new StringBuilder(); ElementSchemaPointerPart part = new ElementSchemaPointerPart(); lexer.NextLexeme(); if (lexer.Kind == XPointerLexer.LexKind.NCName) { xpathBuilder.Append("id('"); xpathBuilder.Append(lexer.NCName); xpathBuilder.Append("')"); lexer.NextLexeme(); } int childSequenceLen = 0; while (lexer.Kind == XPointerLexer.LexKind.Slash) { lexer.NextLexeme(); if (lexer.Kind != XPointerLexer.LexKind.Number) { Debug.WriteLine(Properties.Resources.InvalidTokenInElementSchemeWhileNumberExpected); return null; } if (lexer.Number == 0) { Debug.WriteLine(Properties.Resources.ZeroIndexInElementSchemechildSequence); return null; } childSequenceLen++; xpathBuilder.Append("/*["); xpathBuilder.Append(lexer.Number); xpathBuilder.Append("]"); lexer.NextLexeme(); } if (lexer.Kind != XPointerLexer.LexKind.RRBracket) { throw new XPointerSyntaxException(Properties.Resources.InvalidTokenInElementSchemeWhileClosingRoundBracketExpected); } if (xpathBuilder.Length == 0 && childSequenceLen == 0) { Debug.WriteLine(Properties.Resources.EmptyElementSchemeXPointer); return null; } part.XPath = xpathBuilder.ToString(); return part; }