Exemple #1
0
        /// <summary>
        /// Convert the given source element to typed subclasses of Element, according
        /// to the given ElementFactory.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="factory"></param>
        /// <returns></returns>
        public static Element AddTypes(XmlElement source, ElementFactory factory)
        {
            if (source is Element)
            {
                return((Element)source); // assume all kids are converted already.
            }
            XmlDocument      doc = source.OwnerDocument;
            XmlQualifiedName qn  = new XmlQualifiedName(source.Name, source.NamespaceURI);
            Element          el  = factory.GetElement(source.Prefix, qn, doc);

            el.IsEmpty = source.IsEmpty;

            if (source.HasAttributes)
            {
                foreach (XmlAttribute attr in source.Attributes)
                {
                    el.Attributes.Append((XmlAttribute)attr.CloneNode(true));
                }
            }

            foreach (XmlNode n in source.ChildNodes)
            {
                if (n is XmlElement)
                {
                    el.AppendChild(AddTypes((XmlElement)n, factory));
                }
                else
                {
                    el.AppendChild(n.CloneNode(true));
                }
            }

            return(el);
        }
Exemple #2
0
 public void Test_Error()
 {
     Error err = new Error(doc);
     err.Message = "foo";
     Assert.AreEqual("<stream:error " +
         "xmlns:stream=\"http://etherx.jabber.org/streams\">foo</stream:error>", err.ToString());
     ElementFactory sf = new ElementFactory();
     sf.AddType(new fact());
     XmlQualifiedName qname = new XmlQualifiedName(err.LocalName, err.NamespaceURI);
     Element p = (Element) sf.GetElement(err.Prefix, qname, doc);
     Assert.AreEqual(typeof(Error), p.GetType());
 }
Exemple #3
0
        /// <summary>
        /// Get an element by name using the current factory.
        /// </summary>
        /// <param name="name">The element name to use</param>
        /// <param name="ns">The namespace URI of the element to get</param>
        /// <returns></returns>
        public Element GetElement(string name, string ns)
        {
            XmlQualifiedName q = new XmlQualifiedName(name, ns);

            return(m_factory.GetElement("", q, m_doc));
        }