value,
false);
+ returnEntityReference = false;
return true;
}
#region Internals
// Parsed DTD Objects
internal DTDObjectModel DTD;
+ internal bool MaybeTextDecl {
+ set { if (value) this.maybeTextDecl = 2; }
+ }
#endregion
#region Privates
case ' ':
if (whitespaceHandling == WhitespaceHandling.All ||
whitespaceHandling == WhitespaceHandling.Significant)
- return ReadWhitespace ();
-
- SkipWhitespace ();
- return ReadContent ();
+ ReadWhitespace ();
+ else {
+ SkipWhitespace ();
+ return ReadContent ();
+ }
+ break;
case -1:
if (depth > 0)
throw new XmlException ("unexpected end of file. Current depth is " + depth);
break;
}
}
+ if (NodeType == XmlNodeType.XmlDeclaration && maybeTextDecl == 1)
+ return ReadContent ();
return this.ReadState != ReadState.EndOfFile;
}
ClearAttributes ();
SkipWhitespace ();
- if (XmlConstructs.IsNameStart (PeekChar ()))
+ if (XmlChar.IsFirstNameChar (PeekChar ()))
ReadAttributes (false);
string baseUri = GetAttribute ("xml:base");
Expect (';');
string name = CreateNameString ();
- if (XmlConstructs.IsValidName (name) >= 0)
+ if (!XmlChar.IsName (name))
throw new XmlException (this as IXmlLineInfo,
"Invalid entity reference name was found.");
AddAttribute (name, value);
- if (XmlConstructs.IsSpace (PeekChar ()))
- SkipWhitespace ();
- else
+ if (!SkipWhitespace ())
requireWhitespace = true;
peekChar = PeekChar ();
if (peekChar == '?' && allowPIEnd)
throw new XmlException (this as IXmlLineInfo,
"XML declaration cannot appear in this state.");
}
- currentState = XmlNodeType.XmlDeclaration;
+ // Is this required?
+// if (maybeTextDecl != 0)
+// currentState = XmlNodeType.XmlDeclaration;
ClearAttributes ();
string message = null;
if (parserInputStack.Count == 0) {
- if (orderedAttributes [0] as string != "version" || version != "1.0")
+ if (maybeTextDecl == 0 && (orderedAttributes [0] as string != "version" || version != "1.0"))
message = "Version 1.0 declaration is required in XML Declaration.";
else if (orderedAttributes.Count > 1 &&
(orderedAttributes [1] as string != "encoding" &&
if (this ["standalone"] != null)
throw new XmlException (this as IXmlLineInfo,
"Invalid text declaration.");
- maybeTextDecl = 0;
+ if (maybeTextDecl == 2)
+ maybeTextDecl = 1;
SetProperties (
XmlNodeType.XmlDeclaration, // nodeType
break;
}
+ if (XmlConstructs.IsInvalid (ch))
+ throw new XmlException (this as IXmlLineInfo,
+ "Not allowed character was found.");
+
AppendValueChar ((char)ch);
}
} while (nodeType != XmlNodeType.None || parserInputStack.Count > originalParserDepth + 1);
PopParserInput ();
}
+ // TODO: Check entity nesting
return DTD;
}
}
break;
case ']':
+ if (dtdIncludeSect == 0)
+ throw new XmlException (this as IXmlLineInfo, "Unbalanced end of INCLUDE/IGNORE section.");
// End of inclusion
Expect ("]]>");
dtdIncludeSect--;
LOOPBACK:
if (PeekChar () == '%') {
ReadChar ();
- if (!XmlConstructs.IsSpace (PeekChar ())) {
+ if (!SkipWhitespace ()) {
ExpandPERef ();
goto LOOPBACK;
-// throw new XmlException (this as IXmlLineInfo,"expected whitespace between '%' and name.");
} else {
- SkipWhitespace ();
TryExpandPERef ();
- if (XmlConstructs.IsName (PeekChar ()))
+ if (XmlChar.IsNameChar (PeekChar ()))
ReadParameterEntityDecl ();
else
throw new XmlException (this as IXmlLineInfo,"expected name character");
if(PeekChar () == '#') {
// Mixed Contents. "#PCDATA" must appear first.
decl.IsMixedContent = true;
+ model.Occurence = DTDOccurence.ZeroOrMore;
+ model.OrderType = DTDContentOrderType.Or;
Expect ("#PCDATA");
SkipWhitespace ();
TryExpandPERef ();
TryExpandPERef ();
SkipWhitespace ();
DTDContentModel elem = new DTDContentModel (DTD, decl.Name);
- model.ElementName = ReadName ();
+ elem.ElementName = ReadName ();
model.ChildModels.Add (elem);
SkipWhitespace ();
TryExpandPERef ();
}
Expect (')');
- if (model.ChildModels.Count > 0) {
+ if (model.ChildModels.Count > 0)
Expect ('*');
- model.Occurence = DTDOccurence.ZeroOrMore;
- }
else if (PeekChar () == '*')
Expect ('*');
} else {
sb = new StringBuilder ();
else
sb.Length = 0;
- while (PeekChar () != -1)
+ bool checkTextDecl = true;
+ while (PeekChar () != -1) {
sb.Append (ReadChar ());
+ if (checkTextDecl && sb.Length == 6) {
+ if (sb.ToString () == "<?xml ") {
+ // Skip Text declaration.
+ sb.Length = 0;
+ while (PeekChar () == '>' || PeekChar () == -1)
+ ReadChar ();
+ }
+ }
+ }
PopParserInput ();
appendStr = sb.ToString ();
} else {
// The reader is positioned on the head of the name.
private DTDEntityDeclaration ReadEntityDecl ()
{
- DTDEntityDeclaration decl = new DTDEntityDeclaration ();
+ DTDEntityDeclaration decl = new DTDEntityDeclaration (DTD);
decl.IsInternalSubset = isIntSubset;
decl.Name = ReadName ();
if (!SkipWhitespace ())
}
}
else {
- // general entity
- decl.EntityValue = ReadEntityValueDecl ();
+ // literal entity
+ decl.LiteralEntityValue = ReadEntityValueDecl ();
}
SkipWhitespace ();
// This expanding is only allowed as a non-validating parser.
TryExpandPERef ();
SkipWhitespace ();
- while (XmlConstructs.IsName ((char) PeekChar ())) {
+ while (XmlChar.IsNameChar ((char) PeekChar ())) {
DTDAttributeDefinition def = ReadAttributeDefinition ();
if (decl [def.Name] == null)
decl.Add (def);
}
break;
default: // Enumerated Values
+ def.Datatype = XmlSchemaDatatype.FromName ("string");
TryExpandPERef ();
Expect ('(');
SkipWhitespace ();
{
if (PeekChar () == '%') {
ReadChar ();
- if (!XmlConstructs.IsName (PeekChar ()))
+ if (!XmlChar.IsNameChar (PeekChar ()))
return;
ExpandPERef ();
}
{
DTDParameterEntityDeclaration decl =
parameterEntities [peName] as DTDParameterEntityDeclaration;
- if (decl == null)
- throw new XmlException ("undeclared parameter entity: '" + peName + "'");
+ if (decl == null) {
+ DTD.AddError (new XmlSchemaException (
+ "undeclared parameter entity: '" + peName + "'", null));
+ return;
+ }
if (decl.SystemId != null) {
PushParserInput (decl.SystemId);
// currentInput.InsertParameterEntityBuffer (this.GetExternalTextMarkup (decl));
{
c = ReadChar ();
if(c < 0) throw new XmlException (this as IXmlLineInfo,"Unexpected end of stream in ExternalID.");
- if(c != quoteChar && !XmlConstructs.IsPubid (c))
+ if(c != quoteChar && !XmlChar.IsPubidChar (c))
throw new XmlException (this as IXmlLineInfo,"character '" + (char)c + "' not allowed for PUBLIC ID");
}
return currentTag.ToString (startPos, currentTag.Length - 1 - startPos);
{
int ch = PeekChar ();
if(isNameToken) {
- if (!XmlConstructs.IsName ((char) ch))
+ if (!XmlChar.IsNameChar ((char) ch))
throw new XmlException (this as IXmlLineInfo,String.Format ("a nmtoken did not start with a legal character {0} ({1})", ch, (char)ch));
}
else {
- if (!XmlConstructs.IsNameStart ((char) ch))
+ if (!XmlChar.IsFirstNameChar (ch))
throw new XmlException (this as IXmlLineInfo,String.Format ("a name did not start with a legal character {0} ({1})", ch, (char)ch));
}
AppendNameChar (ReadChar ());
- while (XmlConstructs.IsName (PeekChar ())) {
+ while (XmlChar.IsNameChar (PeekChar ())) {
AppendNameChar (ReadChar ());
}
private bool SkipWhitespace ()
{
//FIXME: Should not skip if whitespaceHandling == WhiteSpaceHandling.None
- bool skipped = XmlConstructs.IsSpace (PeekChar ());
- while (XmlConstructs.IsSpace (PeekChar ()))
+ bool skipped = XmlChar.IsWhitespace (PeekChar ());
+ while (XmlChar.IsWhitespace (PeekChar ()))
ReadChar ();
return skipped;
}
- private bool ReadWhitespace ()
+ private void ReadWhitespace ()
{
if (currentState == XmlNodeType.None)
currentState = XmlNodeType.XmlDeclaration;
int ch = PeekChar ();
do {
AppendValueChar (ReadChar ());
- } while ((ch = PeekChar ()) != -1 && XmlConstructs.IsSpace (ch));
+ } while ((ch = PeekChar ()) != -1 && XmlChar.IsWhitespace (ch));
if (currentState == XmlNodeType.Element && ch != -1 && ch != '<')
ReadText (false);
valueBuffer,
true);
- return (PeekChar () != -1);
+ return; // (PeekChar () != -1);
}
// read entity reference from attribute string and if parsable then return the value.