Esempio n. 1
0
 public override XmlNode CloneNode(bool deep) {
     //CloneNode is deep for attributes irrespective of parameter
     XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute( Prefix, LocalName, NamespaceURI, OwnerDocument );
     attr.CopyChildren( this, true );
     attr.fSpecified = true; //When clone, should return the specifed attribute as default
     return attr;
 }
Esempio n. 2
0
        private XmlAttribute LoadDefaultAttribute()
        {
            Debug.Assert(_reader.IsDefault);

            XmlReader      r          = _reader;
            XmlAttribute   attr       = _doc.CreateDefaultAttribute(r.Prefix, r.LocalName, r.NamespaceURI);
            IXmlSchemaInfo schemaInfo = r.SchemaInfo;

            if (schemaInfo != null)
            {
                attr.XmlName = _doc.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, schemaInfo);
            }

            LoadAttributeValue(attr, false);

            XmlUnspecifiedAttribute defAttr = attr as XmlUnspecifiedAttribute;

            // If user overrides CreateDefaultAttribute, then attr will NOT be a XmlUnspecifiedAttribute instance.
            if (defAttr != null)
            {
                defAttr.SetSpecified(false);
            }

            return(attr);
        }
Esempio n. 3
0
        // Creates a duplicate of this node.
        public override XmlNode CloneNode(bool deep)
        {
            Debug.Assert(OwnerDocument != null);
            XmlDocument doc = OwnerDocument;
            bool        OrigLoadingStatus = doc.IsLoading;

            doc.IsLoading = true;
            XmlElement element = doc.CreateElement(Prefix, LocalName, NamespaceURI);

            doc.IsLoading = OrigLoadingStatus;
            if (element.IsEmpty != this.IsEmpty)
            {
                element.IsEmpty = this.IsEmpty;
            }

            if (HasAttributes)
            {
                foreach (XmlAttribute attr in Attributes)
                {
                    XmlAttribute            newAttr    = (XmlAttribute)(attr.CloneNode(true));
                    XmlUnspecifiedAttribute unspecAttr = newAttr as XmlUnspecifiedAttribute;
                    if (unspecAttr != null && attr.Specified == false)
                    {
                        unspecAttr.SetSpecified(false);
                    }
                    element.Attributes.InternalAppendAttribute(newAttr);
                }
            }
            if (deep)
            {
                element.CopyChildren(doc, this, deep);
            }

            return(element);
        }
Esempio n. 4
0
        public override XmlNode CloneNode(bool deep)
        {
            //CloneNode is deep for attributes irrespective of parameter
            XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute(Prefix, LocalName, NamespaceURI, OwnerDocument);

            attr.CopyChildren(this, true);
            attr.fSpecified = true; //When clone, should return the specifed attribute as default
            return(attr);
        }
Esempio n. 5
0
        public override XmlNode CloneNode(bool deep)
        {
            XmlDocument             ownerDocument = this.OwnerDocument;
            XmlUnspecifiedAttribute attribute     = (XmlUnspecifiedAttribute)ownerDocument.CreateDefaultAttribute(this.Prefix, this.LocalName, this.NamespaceURI);

            attribute.CopyChildren(ownerDocument, this, true);
            attribute.fSpecified = true;
            return(attribute);
        }
Esempio n. 6
0
        private void ValidateAttributes(XmlElement elementNode)
        {
            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attr       = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attr         = attributes[i];
                _currentNode = attr; //For nodeValueGetter to pick up the right attribute value
                if (Ref.Equal(attr.NamespaceURI, _nsXmlNs))
                {                    //Do not validate namespace decls
                    continue;
                }
                _validator.ValidateAttribute(attr.LocalName, attr.NamespaceURI, _nodeValueGetter, _attributeSchemaInfo);
                if (_psviAugmentation)
                {
                    attr.XmlName = _document.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, _attributeSchemaInfo);
                }
            }

            if (_psviAugmentation)
            {
                //Add default attributes to the attributes collection
                if (_defaultAttributes == null)
                {
                    _defaultAttributes = new ArrayList();
                }
                else
                {
                    _defaultAttributes.Clear();
                }
                _validator.GetUnspecifiedDefaultAttributes(_defaultAttributes);
                XmlSchemaAttribute schemaAttribute = null;
                XmlQualifiedName   attrQName;
                attr = null;
                for (int i = 0; i < _defaultAttributes.Count; i++)
                {
                    schemaAttribute = _defaultAttributes[i] as XmlSchemaAttribute;
                    attrQName       = schemaAttribute.QualifiedName;
                    Debug.Assert(schemaAttribute != null);
                    attr = _document.CreateDefaultAttribute(GetDefaultPrefix(attrQName.Namespace), attrQName.Name, attrQName.Namespace);
                    SetDefaultAttributeSchemaInfo(schemaAttribute);
                    attr.XmlName = _document.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, _attributeSchemaInfo);
                    attr.AppendChild(_document.CreateTextNode(schemaAttribute.AttDef.DefaultValueRaw));
                    attributes.Append(attr);
                    XmlUnspecifiedAttribute defAttr = attr as XmlUnspecifiedAttribute;
                    if (defAttr != null)
                    {
                        defAttr.SetSpecified(false);
                    }
                }
            }
        }
        private void ValidateAttributes(XmlElement elementNode)
        {
            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           node       = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                node             = attributes[i];
                this.currentNode = node;
                if (!Ref.Equal(node.NamespaceURI, this.NsXmlNs))
                {
                    this.validator.ValidateAttribute(node.LocalName, node.NamespaceURI, this.nodeValueGetter, this.attributeSchemaInfo);
                    if (this.psviAugmentation)
                    {
                        node.XmlName = this.document.AddAttrXmlName(node.Prefix, node.LocalName, node.NamespaceURI, this.attributeSchemaInfo);
                    }
                }
            }
            if (this.psviAugmentation)
            {
                if (this.defaultAttributes == null)
                {
                    this.defaultAttributes = new ArrayList();
                }
                else
                {
                    this.defaultAttributes.Clear();
                }
                this.validator.GetUnspecifiedDefaultAttributes(this.defaultAttributes);
                XmlSchemaAttribute schemaAttribute = null;
                node = null;
                for (int j = 0; j < this.defaultAttributes.Count; j++)
                {
                    schemaAttribute = this.defaultAttributes[j] as XmlSchemaAttribute;
                    XmlQualifiedName qualifiedName = schemaAttribute.QualifiedName;
                    node = this.document.CreateDefaultAttribute(this.GetDefaultPrefix(qualifiedName.Namespace), qualifiedName.Name, qualifiedName.Namespace);
                    this.SetDefaultAttributeSchemaInfo(schemaAttribute);
                    node.XmlName = this.document.AddAttrXmlName(node.Prefix, node.LocalName, node.NamespaceURI, this.attributeSchemaInfo);
                    node.AppendChild(this.document.CreateTextNode(schemaAttribute.AttDef.DefaultValueRaw));
                    attributes.Append(node);
                    XmlUnspecifiedAttribute attribute3 = node as XmlUnspecifiedAttribute;
                    if (attribute3 != null)
                    {
                        attribute3.SetSpecified(false);
                    }
                }
            }
        }
Esempio n. 8
0
        private XmlAttribute LoadAttributeNodeDirect()
        {
            XmlReader reader = this.reader;

            if (reader.IsDefault)
            {
                XmlUnspecifiedAttribute attribute2 = new XmlUnspecifiedAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                this.LoadAttributeValue(attribute2, true);
                attribute2.SetSpecified(false);
                return(attribute2);
            }
            XmlAttribute parent = new XmlAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);

            this.LoadAttributeValue(parent, true);
            return(parent);
        }
Esempio n. 9
0
        private XmlAttribute LoadAttributeNodeDirect()
        {
            XmlReader    r = _reader;
            XmlAttribute attr;

            if (r.IsDefault)
            {
                XmlUnspecifiedAttribute defattr = new XmlUnspecifiedAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
                LoadAttributeValue(defattr, true);
                defattr.SetSpecified(false);
                return(defattr);
            }
            else
            {
                attr = new XmlAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
                LoadAttributeValue(attr, true);
                return(attr);
            }
        }
Esempio n. 10
0
        private XmlAttribute LoadDefaultAttribute()
        {
            XmlReader      reader     = this.reader;
            XmlAttribute   parent     = this.doc.CreateDefaultAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            IXmlSchemaInfo schemaInfo = reader.SchemaInfo;

            if (schemaInfo != null)
            {
                parent.XmlName = this.doc.AddAttrXmlName(parent.Prefix, parent.LocalName, parent.NamespaceURI, schemaInfo);
            }
            this.LoadAttributeValue(parent, false);
            XmlUnspecifiedAttribute attribute2 = parent as XmlUnspecifiedAttribute;

            if (attribute2 != null)
            {
                attribute2.SetSpecified(false);
            }
            return(parent);
        }
Esempio n. 11
0
        private XmlAttribute LoadDefaultAttribute()
        {
            Debug.Assert(reader.IsDefault);

            XmlReader    r    = reader;
            XmlAttribute attr = doc.CreateDefaultAttribute(r.Prefix, r.LocalName, r.NamespaceURI);

            LoadAttributeValue(attr, false);

            XmlUnspecifiedAttribute defAttr = attr as XmlUnspecifiedAttribute;

            // If user overrides CreateDefaultAttribute, then attr will NOT be a XmlUnspecifiedAttribute instance.
            if (defAttr != null)
            {
                defAttr.SetSpecified(false);
            }

            return(attr);
        }
Esempio n. 12
0
        private XmlAttribute LoadAttributeNode()
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Attribute);

            XmlAttribute attr;

            if (reader.IsDefault)
            {
                attr = doc.CreateDefaultAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                LoadAttributeChildren(attr);
                XmlUnspecifiedAttribute defAttr = attr as XmlUnspecifiedAttribute;
                // If user overrrides CreateDefaultAttribute, then attr will NOT be a XmlUnspecifiedAttribute instance.
                if (defAttr != null)
                {
                    defAttr.SetSpecified(false);
                }
                return(attr);
            }

            attr = doc.CreateAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            LoadAttributeChildren(attr);
            return(attr);
        }
Esempio n. 13
0
 private XmlAttribute LoadAttributeNodeDirect()
 {
     XmlReader r = _reader;
     XmlAttribute attr;
     if (r.IsDefault)
     {
         XmlUnspecifiedAttribute defattr = new XmlUnspecifiedAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
         LoadAttributeValue(defattr, true);
         defattr.SetSpecified(false);
         return defattr;
     }
     else
     {
         attr = new XmlAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
         LoadAttributeValue(attr, true);
         return attr;
     }
 }
Esempio n. 14
0
        private XmlNode LoadEntityChildren() {
            XmlNode node = null;

            // We do not use creator functions on XmlDocument, b/c we do not want to let users extend the nodes that are children of entity nodes (also, if we do
            // this, XmlDataDocument will have a problem, b/c they do not know that those nodes should not be mapped).
            switch (reader.NodeType) {
                case XmlNodeType.EndElement:
                case XmlNodeType.EndEntity:
                    break;

                case XmlNodeType.Element: {
                    bool fEmptyElement = reader.IsEmptyElement;

                    XmlElement element = new XmlElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                    element.IsEmpty = fEmptyElement;

                    while(reader.MoveToNextAttribute()) {
                        XmlAttribute attr = (XmlAttribute) LoadEntityChildren();
                        element.Attributes.Append( attr );
                    }

                    // recursively load all children.
                    if (! fEmptyElement)
                        LoadEntityChildren( element );

                    node = element;
                    break;
                }

                case XmlNodeType.Attribute:
                    if (reader.IsDefault) {
                        XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                        LoadEntityAttributeChildren( attr );
                        attr.SetSpecified( false );
                        node = attr;
                    }
                    else {
                        XmlAttribute attr = new XmlAttribute( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                        LoadEntityAttributeChildren( attr );
                        node = attr;
                    }
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = new XmlSignificantWhitespace( reader.Value, this.doc );
                    break;

                case XmlNodeType.Whitespace:
                    if ( preserveWhitespace )
                        node = new XmlWhitespace( reader.Value, this.doc );
                    else {
                        // if preserveWhitespace is false skip all subsequent WS nodes and position on the first non-WS node
                        do {
                            if (! reader.Read() )
                                return null;
                        } while (reader.NodeType == XmlNodeType.Whitespace);
                        node = LoadEntityChildren();   // Skip WS node if preserveWhitespace is false
                    }
                    break;

                case XmlNodeType.Text:
                    node = new XmlText( reader.Value, this.doc );
                    break;

                case XmlNodeType.CDATA:
                    node = new XmlCDataSection( reader.Value, this.doc );
                    break;

                case XmlNodeType.EntityReference:{
                    XmlEntityReference eref = new XmlEntityReference( reader.Name, this.doc );
                    if ( reader.CanResolveEntity ) {
                        reader.ResolveEntity();
                        LoadEntityChildren( eref );
                        //what if eref doesn't have children at all? should we just put a Empty String text here?
                        if ( eref.ChildNodes.Count == 0 )
                            eref.AppendChild( new XmlText("") );
                    }
                    node = eref;
                    break;
                }

                case XmlNodeType.ProcessingInstruction:
                    node = new XmlProcessingInstruction( reader.Name, reader.Value, this.doc );
                    break;

                case XmlNodeType.Comment:
                    node = new XmlComment( reader.Value, this.doc );
                    break;

                default:
                    throw new InvalidOperationException(string.Format(Res.GetString(Res.Xdom_Load_NodeType),reader.NodeType.ToString()));
            }

            return node;
        }
Esempio n. 15
0
        private XmlNode LoadEntityChildren()
        {
            XmlNode node = null;

            // We do not use creator functions on XmlDocument, b/c we do not want to let users extend the nodes that are children of entity nodes (also, if we do
            // this, XmlDataDocument will have a problem, b/c they do not know that those nodes should not be mapped).
            switch (reader.NodeType)
            {
            case XmlNodeType.EndElement:
            case XmlNodeType.EndEntity:
                break;

            case XmlNodeType.Element: {
                bool fEmptyElement = reader.IsEmptyElement;

                XmlElement element = new XmlElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                element.IsEmpty = fEmptyElement;

                while (reader.MoveToNextAttribute())
                {
                    XmlAttribute attr = (XmlAttribute)LoadEntityChildren();
                    element.Attributes.Append(attr);
                }

                // recursively load all children.
                if (!fEmptyElement)
                {
                    LoadEntityChildren(element);
                }

                node = element;
                break;
            }

            case XmlNodeType.Attribute:
                if (reader.IsDefault)
                {
                    XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    attr.SetSpecified(false);
                    node = attr;
                }
                else
                {
                    XmlAttribute attr = new XmlAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    node = attr;
                }
                break;

            case XmlNodeType.SignificantWhitespace:
                node = new XmlSignificantWhitespace(reader.Value, this.doc);
                break;

            case XmlNodeType.Whitespace:
                if (preserveWhitespace)
                {
                    node = new XmlWhitespace(reader.Value, this.doc);
                }
                else
                {
                    // if preserveWhitespace is false skip all subsequent WS nodes and position on the first non-WS node
                    do
                    {
                        if (!reader.Read())
                        {
                            return(null);
                        }
                    } while (reader.NodeType == XmlNodeType.Whitespace);
                    node = LoadEntityChildren();       // Skip WS node if preserveWhitespace is false
                }
                break;

            case XmlNodeType.Text:
                node = new XmlText(reader.Value, this.doc);
                break;

            case XmlNodeType.CDATA:
                node = new XmlCDataSection(reader.Value, this.doc);
                break;

            case XmlNodeType.EntityReference: {
                XmlEntityReference eref = new XmlEntityReference(reader.Name, this.doc);
                if (reader.CanResolveEntity)
                {
                    reader.ResolveEntity();
                    LoadEntityChildren(eref);
                    //what if eref doesn't have children at all? should we just put a Empty String text here?
                    if (eref.ChildNodes.Count == 0)
                    {
                        eref.AppendChild(new XmlText(""));
                    }
                }
                node = eref;
                break;
            }

            case XmlNodeType.ProcessingInstruction:
                node = new XmlProcessingInstruction(reader.Name, reader.Value, this.doc);
                break;

            case XmlNodeType.Comment:
                node = new XmlComment(reader.Value, this.doc);
                break;

            default:
                throw new InvalidOperationException(string.Format(Res.GetString(Res.Xdom_Load_NodeType), reader.NodeType.ToString()));
            }

            return(node);
        }
 private XmlAttribute LoadAttributeNodeDirect()
 {
     XmlReader reader = this.reader;
     if (reader.IsDefault)
     {
         XmlUnspecifiedAttribute attribute2 = new XmlUnspecifiedAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
         this.LoadAttributeValue(attribute2, true);
         attribute2.SetSpecified(false);
         return attribute2;
     }
     XmlAttribute parent = new XmlAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
     this.LoadAttributeValue(parent, true);
     return parent;
 }