Ejemplo n.º 1
0
        void IContentHandler.StartElement(string uri, string localName, string qName, IAttributes atts)
        {
            XmlQualifiedName q = new XmlQualifiedName(localName, uri);

            XmlElement elem = m_factory.GetElement(Prefix(qName), q, m_doc);

            for (int i = 0; i < atts.Length; i++)
            {
                XmlAttribute a = m_doc.CreateAttribute(Prefix(atts.GetQName(i)),
                                                       atts.GetLocalName(i),
                                                       atts.GetUri(i));
                a.AppendChild(m_doc.CreateTextNode(atts.GetValue(i)));
                elem.SetAttributeNode(a);
            }

            if ((elem.LocalName != "stream") || (elem.NamespaceURI != URI.STREAM))
            {
                if (m_stanza != null)
                {
                    m_stanza.AppendChild(elem);
                }
                m_stanza = elem;
            }
            else
            {
                FireOnDocumentStart(elem);
            }
        }
Ejemplo n.º 2
0
        void IContentHandler.StartElement(string uri, string localName, string qName, IAttributes atts)
        {
            XmlQualifiedName q  = new XmlQualifiedName(localName, uri);

            XmlElement elem = m_factory.GetElement(Prefix(qName), q, m_doc);
            for (int i=0; i<atts.Length; i++)
            {
                XmlAttribute a = m_doc.CreateAttribute(Prefix(atts.GetQName(i)),
                    atts.GetLocalName(i),
                    atts.GetUri(i));
                a.AppendChild(m_doc.CreateTextNode(atts.GetValue(i)));
                elem.SetAttributeNode(a);
            }

            if ((elem.LocalName != "stream") || (elem.NamespaceURI != URI.STREAM))
            {
                if (m_stanza != null)
                    m_stanza.AppendChild(elem);
                m_stanza = elem;
            }
            else
            {
                FireOnDocumentStart(elem);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Copy a whole set of attributes.</summary>
        public virtual void SetAttributes(IAttributes atts)
        {
            if (atts == null)
            {
                throw new ArgumentNullException("atts");
            }
            Clear();
            int attLen = atts.Length;

            if (Capacity < attLen)
            {
                Capacity = attLen;
            }
            for (int attIndx = 0; attIndx < attLen; attIndx++)
            {
                InternalSetAttribute(
                    ref this.atts[attIndx],
                    atts.GetUri(attIndx),
                    atts.GetLocalName(attIndx),
                    atts.GetQName(attIndx),
                    atts.GetType(attIndx),
                    atts.GetValue(attIndx),
                    atts.IsSpecified(attIndx));
            }
        }
Ejemplo n.º 4
0
 public void StartElement(String namespaceURI, String localName, String qName, IAttributes atts) {
   Console.WriteLine("  EVENT: startElement " + makeNSName(namespaceURI, localName, qName));
   int attLen = atts.Length;
   for (int i = 0; i < attLen; i++) {
     char[] ch = atts.GetValue(i).ToCharArray();
     Console.WriteLine("    Attribute " + makeNSName(atts.GetUri(i), atts.GetLocalName(i), atts.GetQName(i)) + '='
                       + escapeData(ch, 0, ch.Length));
   }
 }
Ejemplo n.º 5
0
        public void StartElement(String namespaceURI, String localName, String qName, IAttributes atts)
        {
            Console.WriteLine("  EVENT: startElement " + makeNSName(namespaceURI, localName, qName));
            int attLen = atts.Length;

            for (int i = 0; i < attLen; i++)
            {
                char[] ch = atts.GetValue(i).ToCharArray();
                Console.WriteLine("    Attribute " + makeNSName(atts.GetUri(i), atts.GetLocalName(i), atts.GetQName(i)) + '='
                                  + escapeData(ch, 0, ch.Length));
            }
        }
Ejemplo n.º 6
0
 /// <summary>Add an attribute taken from an existing set of attributes.</summary>
 /// <returns>Index of added attribute.</returns>
 public virtual int AddAttribute(IAttributes atts, int index)
 {
     if (atts == null)
     {
         throw new ArgumentNullException("atts");
     }
     return(AddAttribute(
                atts.GetUri(index),
                atts.GetLocalName(index),
                atts.GetQName(index),
                atts.GetType(index),
                atts.GetValue(index),
                atts.IsSpecified(index)));
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Write out an attribute list, escaping values.
 ///     The names will have prefixes added to them.
 /// </summary>
 /// <param name="atts">
 ///     The attribute list to write.
 /// </param>
 /// <exception cref="SAXException">
 ///     If there is an error writing
 ///     the attribute list, this method will throw an
 ///     IOException wrapped in a SAXException.
 /// </exception>
 private void WriteAttributes(IAttributes atts)
 {
     int len = atts.Length;
     for (int i = 0; i < len; i++) {
       char[] ch = atts.GetValue(i).ToCharArray();
       Write(' ');
       WriteName(atts.GetUri(i), atts.GetLocalName(i), atts.GetQName(i), false);
       if (_htmlMode && BoolAttribute(atts.GetLocalName(i), atts.GetQName(i), atts.GetValue(i))) {
     break;
       }
       Write("=\"");
       WriteEsc(ch, 0, ch.Length, true);
       Write('"');
     }
 }
Ejemplo n.º 8
0
        private void SetAttributesInternal(IAttributes atts)
        {
            ClearInternal();
            int length = atts.Length;

            if (length > 0)
            {
                _data = new string[length * 5];

                for (int i = 0; i < length; i++)
                {
                    _data[i * 5]     = atts.GetUri(i);
                    _data[i * 5 + 1] = atts.GetLocalName(i);
                    _data[i * 5 + 2] = atts.GetQName(i);
                    _data[i * 5 + 3] = atts.GetType(i);
                    _data[i * 5 + 4] = atts.GetValue(i);
                }
                _length = length;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Element构造函数
        /// </summary>
        /// <param name="uri">资源地址</param>
        /// <param name="localName">本地名称(uri有值时tagname为此值)</param>
        /// <param name="qName">q名称(uri为空时tagname为此值)</param>
        /// <param name="attributes">特性集合,可以为null</param>
        /// <param name="locator">定位可以为null</param>
        public Element(string uri, string localName, string qName, IAttributes attributes, ILocator locator)
        {
            this.uri = uri;
            tagName  = string.IsNullOrEmpty(uri) ? qName : localName;

            if (attributes != null)
            {
                for (var i = 0; i < attributes.GetLength(); i++)
                {
                    var attributeUri = attributes.GetUri(i);
                    var name         = string.IsNullOrEmpty(attributeUri) ? attributes.GetQName(i) : attributes.GetLocalName(i);
                    var value        = attributes.GetValue(i);
                    AttributeMap[ComposeMapKey(attributeUri, name)] = new Attribute(name, value, attributeUri);
                }
            }

            if (locator != null)
            {
                line   = locator.GetLineNumber();   //.LineNumber;
                column = locator.GetColumnNumber(); //.ColumnNumber;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Write out an attribute list, escaping values.
 ///     The names will have prefixes added to them.
 /// </summary>
 /// <param name="atts">
 ///     The attribute list to write.
 /// </param>
 /// <exception cref="SAXException">
 ///     If there is an error writing
 ///     the attribute list, this method will throw an
 ///     IOException wrapped in a SAXException.
 /// </exception>
 private void WriteAttributes(IAttributes atts) {
   int len = atts.Length;
   for (int i = 0; i < len; i++) {
     char[] ch = atts.GetValue(i).ToCharArray();
     Write(' ');
     WriteName(atts.GetUri(i), atts.GetLocalName(i), atts.GetQName(i), false);
     if (_htmlMode && BoolAttribute(atts.GetLocalName(i), atts.GetQName(i), atts.GetValue(i))) {
       break;
     }
     Write("=\"");
     WriteEsc(ch, 0, ch.Length, true);
     Write('"');
   }
 }
Ejemplo n.º 11
0
        public void StartElement(string uri, string localName, string qName, IAttributes atts)
        {
            seenEvent = true;
              if (inProlog)
              {
            FlushProlog();
            inProlog = false;
              }

              FlushEndPrefixMappings();
              if (startPrefixMappings != null)
              {
            for (int i = 0; i < startPrefixMappings.Count; i++)
            {
              string[] mapping = (string[])startPrefixMappings.GetByIndex(i);
              writer.WriteStartElement("startPrefixMapping");
              writer.WriteStartElement("prefix");
              writer.WriteString(mapping[0]);
              writer.WriteEndElement();
              writer.WriteStartElement("data");
              writer.WriteString(mapping[1]);
              writer.WriteEndElement();
              writer.WriteEndElement();
            }
            startPrefixMappings = null;
              }

              writer.WriteStartElement("startElement");

              if (uri != null)
              {
            writer.WriteStartElement("namespaceURI");
            writer.WriteString(uri);
            writer.WriteEndElement();
              }
              if (localName != null)
              {
            writer.WriteStartElement("localName");
            writer.WriteString(localName);
            writer.WriteEndElement();
              }
              if (qName != null)
              {
            writer.WriteStartElement("qualifiedName");
            writer.WriteString(qName);
            writer.WriteEndElement();
              }

              writer.WriteStartElement("attributes");
              SortedList sortedAtts = new SortedList();
              for (int i = 0; i < atts.Length; i++)
              {
            string ln = atts.GetLocalName(i);
            string qn = atts.GetQName(i);
            string ns = atts.GetUri(i);
            string key = "";
            if (ln != null) key += ln;
            key += '\u0000';
            if (qn != null) key += qn;
            key += '\u0000';
            if (ns != null) key += ns;
            sortedAtts.Add(key, i);
              }

              for (int i = 0; i < sortedAtts.Count; i++)
              {
            int index = (int)sortedAtts.GetByIndex(i);
            string ln = atts.GetLocalName(i);
            string qn = atts.GetQName(i);
            string ns = atts.GetUri(i);
            string val = atts.GetValue(i);
            string typ = atts.GetType(i);
            writer.WriteStartElement("attribute");

            if (ns != null)
            {
              writer.WriteStartElement("namespaceURI");
              writer.WriteString(ns);
              writer.WriteEndElement();
            }
            if (ln != null)
            {
              writer.WriteStartElement("localName");
              writer.WriteString(ln);
              writer.WriteEndElement();
            }
            if (qn != null)
            {
              writer.WriteStartElement("qualifiedName");
              writer.WriteString(qn);
              writer.WriteEndElement();
            }
            writer.WriteStartElement("value");
            writer.WriteString(Escape(val));
            writer.WriteEndElement();
            writer.WriteStartElement("type");
            writer.WriteString(Escape(typ));
            writer.WriteEndElement();

            writer.WriteEndElement();
              }
              writer.WriteEndElement();
              writer.WriteEndElement();
        }
Ejemplo n.º 12
0
     public override void StartElement(string uri, string localName, string arg2,
 IAttributes arg3)
     {
         string prefix=getPrefix(arg2);
           Element element=new Element();
           element.setLocalName(localName);
           if(prefix.Length>0){
         element.setPrefix(prefix);
           }
           if(uri!=null && uri.Length>0){
         element.setNamespace(uri);
           }
           getCurrentNode().appendChild(element);
           for(int i=0;i<arg3.Length;i++){
         string _namespace=arg3.GetUri(i);
         Attr attr=new Attr();
         attr.setName(arg3.GetQName(i)); // Sets prefix and local name
         attr.setNamespace(_namespace);
         attr.setValue(arg3.GetValue(i));
         element.addAttribute(attr);
         if("xml:base".Equals(arg3.GetQName(i))){
           xmlBaseElements.Add(element);
         }
           }
           if("http://www.w3.org/1999/xhtml".Equals(uri) &&
           "base".Equals(localName)){
         string href=element.getAttributeNS("", "href");
         if(href!=null) {
           baseurl=href;
         }
           }
           elements.Add(element);
     }
Ejemplo n.º 13
0
    private void SetAttributesInternal(IAttributes atts) {
      ClearInternal();
      int length = atts.Length;
      if (length > 0) {
        _data = new string[length * 5];

        for (int i = 0; i < length; i++) {
          _data[i * 5] = atts.GetUri(i);
          _data[i * 5 + 1] = atts.GetLocalName(i);
          _data[i * 5 + 2] = atts.GetQName(i);
          _data[i * 5 + 3] = atts.GetType(i);
          _data[i * 5 + 4] = atts.GetValue(i);
        }
        _length = length;
      }
    }