+2003-10-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+ * DTDReader.cs, DTDValidatingReader.cs, XmlInputStream.cs,
+ XmlTextReader.cs : More cleanup.
+ * XmlDocument.cs : Removed CheckName(). Code cleanup.
+ * XmlElement.cs : .ctor() now adds default attributes (if required).
+ * XmlAttribute.cs, XmlElement.cs, XmlEntity.cs, XmlEntityReference.cs,
+ XmlNotation.cs : Now uses OwnerDocument's NameTable.
+
2003-10-25 Pedro MartÃnez Juliá <yoros@wanadoo.es>
* XmlConvert.cs: Support for the sign in double and single. The
if (!breakup) {
try {
parsed = def.Datatype.ParseValue (normalized, DTD.NameTable, null);
- } catch (Exception ex) { // FIXME: bad catch ;-(
+ } catch (Exception ex) { // FIXME: (wishlist) bad catch ;-(
DTD.AddError (new XmlSchemaException ("Invalid default value for ENTITY type.",
def.LineNumber, def.LinePosition, null, def.BaseURI, ex));
breakup = true;
// Does not consume the first non-whitespace character.
private bool SkipWhitespace ()
{
- //FIXME: Should not skip if whitespaceHandling == WhiteSpaceHandling.None
bool skipped = XmlChar.IsWhitespace (PeekChar ());
while (XmlChar.IsWhitespace (PeekChar ()))
ReadChar ();
ReadChar (); // ';'
- // FIXME: how to handle such chars larger than 0xffff?
+ // There is no way to save surrogate pairs...
if (value < 0xffff && !XmlConstructs.IsValid (value))
throw new XmlException (this as IXmlLineInfo,
"Referenced character was not allowed in XML.");
parserInputStack.Push (currentInput);
try {
currentInput = new XmlParserInput (new XmlStreamReader (url, false, DTD.Resolver, DTD.BaseURI), absPath);
- } catch (Exception ex) { // FIXME: Bad exception catch ;-(
+ } catch (Exception ex) { // FIXME: (wishlist) Bad exception catch ;-(
int line = currentInput == null ? 0 : currentInput.LineNumber;
int col = currentInput == null ? 0 : currentInput.LinePosition;
string bu = (currentInput == null) ? String.Empty : currentInput.BaseURI;
return false;
}
- [MonoTODO ("Handling of whitespace entities are still not enough.")]
public override bool Read ()
{
if (currentTextValue != null)
if (currentAutomata == DTD.Invalid) {
HandleError (String.Format ("Invalid start element found: {0}", reader.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
currentAutomata = previousAutomata;
}
DTDElementDeclaration decl = DTD.ElementDecls [reader.Name];
if (decl == null) {
HandleError (String.Format ("Element {0} is not declared.", reader.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
currentAutomata = previousAutomata;
}
HandleError (String.Format (
"Attributes are found on element {0} while it has no attribute definitions.", currentElement),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
}
SetupValidityIgnorantAttributes ();
}
if (decl == null) {
HandleError (String.Format ("Element {0} is not declared.", reader.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
}
previousAutomata = currentAutomata;
if (tmpAutomata == DTD.Invalid) {
HandleError (String.Format ("Invalid end element found: {0}", reader.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
currentAutomata = previousAutomata;
}
} else
break;
}
- // FIXME: Should recursively resolve entities.
switch (targetReader.NodeType) {
case XmlNodeType.EntityReference:
DTDEntityDeclaration edecl = DTD.EntityDecls [targetReader.Name];
if (def == null) {
HandleError (String.Format ("Attribute {0} is not declared.", reader.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
} else {
// check enumeration constraint
if (def.EnumeratedAttributeDeclaration.Count > 0)
HandleError (String.Format ("Fixed attribute {0} in element {1} has invalid value {2}.",
def.Name, decl.Name, attrValue),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
}
}
}
HandleError (String.Format ("Required attribute {0} in element {1} not found .",
def.Name, decl.Name),
XmlSeverityType.Error);
- // FIXME: validation recovery code here.
}
else if (def.DefaultValue != null) {
if (this.isStandalone && !def.IsInternalSubset)
else if (!XmlChar.IsName (localName))
throw new ArgumentException ("Invalid attribute local name.");
- this.prefix = prefix;
- this.localName = localName;
- this.namespaceURI = namespaceURI;
+ this.prefix = doc.NameTable.Add (prefix);
+ this.localName = doc.NameTable.Add (localName);
+ this.namespaceURI = doc.NameTable.Add (namespaceURI);
}
#endregion
{
if ((localName == null) || (localName == String.Empty))
throw new ArgumentException ("The local name for elements or attributes cannot be null or an empty string.");
- CheckName (localName);
+ // FIXME: MS.NET has a weird behavior that they can Load() from XmlTextReader
+ // whose Namespaces = false, but their CreateElement() never allows qualified name.
+ // I leave it as it is.
+ if (!XmlChar.IsName (localName))
+ throw new ArgumentException ("Invalid name.", "localName");
return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this);
}
case XmlNodeType.Attribute: return CreateAttribute (prefix, name, namespaceURI);
case XmlNodeType.CDATA: return CreateCDataSection (null);
case XmlNodeType.Comment: return CreateComment (null);
- case XmlNodeType.Document: return new XmlDocument (); // TODO - test to see which constructor to use, i.e. use existing NameTable or not.
+ case XmlNodeType.Document: return new XmlDocument ();
case XmlNodeType.DocumentFragment: return CreateDocumentFragment ();
case XmlNodeType.DocumentType: return CreateDocumentType (null, null, null, null);
case XmlNodeType.Element: return CreateElement (prefix, name, namespaceURI);
}
}
- // Checks that Element's name is valid
- private void CheckName (String name)
- {
- // TODO: others validations?
- if (name.IndexOf (" ") >= 0)
- throw new XmlException ("The ' ' characted cannot be included in a name");
- }
-
// Reads XmlReader and creates Attribute Node.
private XmlAttribute ReadAttributeNode(XmlReader reader)
{
using System.Xml.XPath;
using System.IO;
using System.Text;
+using Mono.Xml;
namespace System.Xml
{
string namespaceURI,
XmlDocument doc) : base (doc)
{
- this.prefix = prefix;
- this.localName = localName;
- this.namespaceURI = namespaceURI;
+ this.prefix = doc.NameTable.Add (prefix);
+ this.localName = doc.NameTable.Add (localName);
+ this.namespaceURI = doc.NameTable.Add (namespaceURI);
attributes = new XmlAttributeCollection (this);
- // TODO: Adds default attributes
if(doc.DocumentType != null)
{
+ DTDAttListDeclaration attlist = doc.DocumentType.DTD.AttListDecls [localName];
+ if (attlist != null) {
+ for (int i = 0; i < attlist.Definitions.Count; i++) {
+ DTDAttributeDefinition def = attlist [i];
+ if (def.DefaultValue != null)
+ SetAttribute (def.Name, def.DefaultValue);
+ }
+ }
}
}
XmlDocument doc)
: base (doc)
{
- this.name = name;
+ this.name = doc.NameTable.Add (name);
this.NDATA = NDATA;
this.publicId = publicId;
this.systemId = systemId;
protected internal XmlEntityReference (string name, XmlDocument doc)\r
: base (doc)\r
{\r
- entityName = name;\r
+ entityName = doc.NameTable.Add (name);\r
}\r
\r
// Properties\r
c = SkipWhitespace (ms);
// version. It is optional here.
- if (c != 'v') {
- // FIXME: temporarily comment out here.
-// if (isDocumentEntity)
-// throw new XmlException ("invalid xml declaration.");
- } else {
+ if (c == 'v') {
ms.WriteByte ((byte)'v');
while (loop++ >= 0 && c >= 0) {
c = stream.ReadByte ();
string systemId, XmlDocument doc)
: base (doc)
{
- this.localName = localName;
- this.prefix = prefix;
+ this.localName = doc.NameTable.Add (localName);
+ this.prefix = doc.NameTable.Add (prefix);
this.publicId = publicId;
this.systemId = systemId;
}
ReadChar (); // ';'
- // FIXME: how to handle such chars larger than 0xffff?
+ // There is no way to save surrogate pairs...
if (normalization && value < 0xffff && !XmlConstructs.IsValid (value))
throw new XmlException (this as IXmlLineInfo,
"Referenced character was not allowed in XML.");
// Does not consume the first non-whitespace character.
private bool SkipWhitespace ()
{
- //FIXME: Should not skip if whitespaceHandling == WhiteSpaceHandling.None
bool skipped = XmlChar.IsWhitespace (PeekChar ());
while (XmlChar.IsWhitespace (PeekChar ()))
ReadChar ();