示例#1
0
 public virtual void StartElement(string uri, string localName, string qName, IAttributes atts)
 {
     if (_contentHandler != null)
     {
         _contentHandler.StartElement(uri, localName, qName, atts);
     }
 }
示例#2
0
        internal void startElement(string elname)
        {
            IContentHandler handler = contentHandler;

            string localName = string.Empty;
            string ns        = string.Empty;

            if (!attributes)
            {
            }
            else if (namespaces)
            {
                // now we can patch up namespace refs; we saw all the
                // declarations, so now we'll do the Right Thing
                for (int i = 0; i < attributeCount; i++)
                {
                    AttributeData att = attributeData[i];

                    // NS prefix declaration?
                    if (att.Declaration && !xmlNames)
                    {
                        continue;
                    }

                    // it's not a NS decl; patch namespace info items
                    processAttribute(att.QName, out localName, out ns);
                    att.Uri       = ns;
                    att.LocalName = localName;

                    for (int j = 0; j < i; j++)
                    {
                        if (att.Uri == attributeData[j].Uri &&
                            att.LocalName == attributeData[j].LocalName)
                        {
                            if (att.Uri != null && att.Uri != "")
                            {
                                fatal("duplicate attribute {" + att.Uri + "}" + att.LocalName);
                            }
                            else
                            {
                                fatal("duplicate attribute \"" + att.LocalName + "\"");
                            }
                        }
                    }
                }
            }

            // save element name so attribute callbacks work
            elementName = elname;
            if (namespaces)
            {
                processElement(elname, out localName, out ns);
                handler.StartElement(ns, localName, elname, this);
            }
            else
            {
                handler.StartElement("", "", elname, this);
            }

            // elements with no attributes are pretty common!
            if (attributes)
            {
                attributeCount = 0;
                attributes     = false;
            }
        }
示例#3
0
        public virtual void StartElement(string elname)
        {
            IContentHandler handler = _contentHandler;

            if (_attributeCount == 0)
            {
                _prefixStack.PushContext();
            }

            // save element name so attribute callbacks work
            _elementName = elname;
            if (_namespaces)
            {
                // Expand namespace prefix for all attributes
                if (_attributeCount > 0)
                {
                    for (int i = 0; i < _attributeNames.Count; i++)
                    {
                        var aname = (string)_attributeNames[i];
                        if (aname.IndexOf(':') > 0)
                        {
                            if (_xmlNames && aname.StartsWith("xmlns:"))
                            {
                                _attributeNamespaces.Add("");
                                _attributeLocalNames.Add(aname);
                            }
                            else if (_prefixStack.ProcessName(aname, _nsTemp, true) == null)
                            {
                                _errorHandler.Error(new SAXParseException("undeclared name prefix in: " + aname, this));
                                // recovery action: substitute a name in default namespace
                                _attributeNamespaces.Add("");
                                _attributeLocalNames.Add(aname.Substring(aname.IndexOf(':') + 1));
                            }
                            else
                            {
                                _attributeNamespaces.Add(_nsTemp[0]);
                                _attributeLocalNames.Add(_nsTemp[1]);
                            }
                        }
                        else
                        {
                            _attributeNamespaces.Add("");
                            _attributeLocalNames.Add(aname);
                        }
                        // check uniquess of the attribute expanded name
                        for (int j = 0; j < i; j++)
                        {
                            if (_attributeNamespaces[i] == _attributeNamespaces[j] &&
                                _attributeLocalNames[i] == _attributeLocalNames[j])
                            {
                                _errorHandler.Error(new SAXParseException("duplicate attribute name: " + _attributeLocalNames[j], this));
                            }
                        }
                    }
                }

                if (_prefixStack.ProcessName(elname, _nsTemp, false) == null)
                {
                    _errorHandler.Error(new SAXParseException("undeclared name prefix in: " + elname, this));
                    _nsTemp[0] = _nsTemp[1] = "";
                    // recovery action
                    elname = elname.Substring(elname.IndexOf(':') + 1);
                }
                handler.StartElement(_nsTemp[0], _nsTemp[1], elname, this);
            }
            else
            {
                handler.StartElement("", "", elname, this);
            }
            // elementName = null;

            // elements with no attributes are pretty common!
            if (_attributeCount != 0)
            {
                _attributeNames.Clear();
                _attributeNamespaces.Clear();
                _attributeLocalNames.Clear();
                _attributeValues.Clear();
                _attributeCount = 0;
            }
            _nspending = false;
        }