[Mono-dev] Bug with System.Xml.XmlDocument.CreateAttribute(, , ) overloading

Markus Mauhart mmauhart at chello.at
Fri Dec 8 13:20:24 EST 2006


Hi,


I have 2 .NET 2.0 applications, using my own derived MyXmlDocument which
overload some CreateXxxx functions to insert MyXmlXxxxx nodes into the tree.
But tested with MONO 1.2.2.1 and 1.18, MyXmlDocument::CreateAttribute(,,)
is not called when loading from XmlReader.

AFAICS, the problem lies in function ...
    private XmlAttribute ReadAttributeNode (XmlReader reader)
... which doesnt call the official virtual "CreateAttribute(,,)",
instead it calls the internal
    "CreateAttribute(,,,bool atomizedNames, bool checkNamespace)":


    private XmlAttribute ReadAttributeNode (XmlReader reader)
    {
        if (reader.NodeType == XmlNodeType.Element)
            reader.MoveToFirstAttribute ();
        else if (reader.NodeType != XmlNodeType.Attribute)
            throw new InvalidOperationException (MakeReaderErrorMessage
                            ("bad position to read attribute.", reader));
--->    XmlAttribute attribute = CreateAttribute
                                    (reader.Prefix, reader.LocalName
                                    , reader.NamespaceURI
                                    , false, false); // different NameTable


The official virtual "CreateAttribute(,,)" implementation uses other flags:

    public virtual XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI)
    {
--->    return CreateAttribute (prefix, localName, namespaceURI, false, true);
    }


Looking into "XmlAttribute(,,,bool atomizedNames, bool checkNamespace)",
IMHO the "checkNamespace == false" in ReadAttributeNode(,,) looks like an
optimization for me, no necessity.
Hence I suggest in ReadAttributeNode() to replace the call of the internal
CreateAttribute(,,,,) with a call of the official virtual CreateAttribute(,,).


Regards,
Markus.




More information about the Mono-devel-list mailing list