RemoveAllAttributes() public method

Removes all the attributes from this element. This can only be used on database nodes. If the node is invalid this does nothing.
The node is not a database node.
public RemoveAllAttributes ( ) : void
return void
示例#1
0
        internal override void Store(Element element, object serialized, object source, TypeCache typeCache, Cache cache)
        {
            if (source == null || serialized == null) return;

            // Replace the element content in the database with the new content
            using (TextReader textReader = new StringReader((string)serialized))
            {
                using(XmlReader reader = XmlReader.Create(textReader))
                {
                    // Move to the root element
                    reader.MoveToContent();

                    // Replace all attributes
                    element.RemoveAllAttributes();
                    if(reader.HasAttributes)
                    {
                        while(reader.MoveToNextAttribute())
                        {
                            element.InsertAttribute(reader.Name, reader.Value);
                        }
                        reader.MoveToElement();
                    }

                    // Replace the child content
                    // Need to use an intermediate string since there is no way to
                    // get the "inner XML" of an XmlReader without getting the
                    // parent element too
                    element.InnerXml = reader.ReadInnerXml();
                }
            }
        }