예제 #1
0
        internal void endElement(string elname)
        {
            IContentHandler handler = contentHandler;

            if (!namespaces)
            {
                handler.EndElement("", "", elname);
                return;
            }

            string localName = string.Empty;
            string uri       = string.Empty;

            processElement(elname, out localName, out uri);
            handler.EndElement(uri, localName, elname);

            ArrayList declared = namespaceSupport.GetDeclaredPrefixes();

            foreach (string prefix in declared)
            {
                handler.EndPrefixMapping(prefix);
            }

            popContext();
        }
예제 #2
0
        public virtual void EndElement(string elname)
        {
            IContentHandler handler = _contentHandler;

            if (!_namespaces)
            {
                handler.EndElement("", "", elname);
                return;
            }

            // following code added by MHK to fix bug Saxon 6.1/013
            if (_prefixStack.ProcessName(elname, _nsTemp, false) == null)
            {
                // shouldn't happen
                _errorHandler.Error(new SAXParseException("undeclared name prefix in: " + elname, this));
                _nsTemp[0] = _nsTemp[1] = "";
                elname     = elname.Substring(elname.IndexOf(':') + 1);
            }

            handler.EndElement(_nsTemp[0], _nsTemp[1], elname);

            // previous code (clearly wrong): handler.endElement ("", "", elname);

            // end of MHK addition

            IEnumerator prefixes = _prefixStack.GetDeclaredPrefixes().GetEnumerator();

            while (prefixes.MoveNext())
            {
                handler.EndPrefixMapping((string)prefixes.Current);
            }
            _prefixStack.PopContext();
        }
예제 #3
0
 public virtual void EndPrefixMapping(string prefix)
 {
     if (_contentHandler != null)
     {
         _contentHandler.EndPrefixMapping(prefix);
     }
 }
예제 #4
0
        public virtual void Parse(TextReader text)
        {
            Stack             nsstack      = new Stack();
            Locator           locator      = new Locator();
            SAXParseException saxException = new SAXParseException();
            Attributes        atts         = new Attributes();
            XmlTextReader     reader       = null;

            try
            {
                reader = new XmlTextReader(text);
                object nsuri = reader.NameTable.Add(
                    "http://www.w3.org/2000/xmlns/");
                handler.StartDocument();
                while (reader.Read())
                {
                    string prefix = "";
                    locator.LineNumber   = reader.LineNumber;
                    locator.ColumnNumber = reader.LinePosition;
                    handler.SetDocumentLocator(locator);
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        nsstack.Push(null);     //marker
                        atts = new Attributes();
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.NamespaceURI.Equals(nsuri))
                            {
                                prefix = "";
                                if (reader.Prefix == "xmlns")
                                {
                                    prefix = reader.LocalName;
                                }
                                nsstack.Push(prefix);
                                handler.StartPrefixMapping(prefix, reader.Value);
                            }
                            else
                            {
                                atts.AddAttribute(reader.NamespaceURI, reader.Name, reader.Name, reader.GetType().ToString(), reader.Value);
                            }
                        }
                        reader.MoveToElement();
                        Handler.StartElement(reader.NamespaceURI, reader.LocalName, reader.Name, atts);
                        if (reader.IsEmptyElement)
                        {
                            handler.EndElement(reader.NamespaceURI, reader.LocalName, reader.Name);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        handler.EndElement(reader.NamespaceURI, reader.LocalName, reader.Name);
                        while (prefix != null)
                        {
                            handler.EndPrefixMapping(prefix);
                            prefix = (string)nsstack.Pop();
                        }
                        break;

                    case XmlNodeType.Text:
                        handler.Characters(reader.Value.ToCharArray(), 0, reader.Value.Length);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        handler.ProcessingInstruction(reader.Name, reader.Value);
                        break;

                    case XmlNodeType.Whitespace:
                        char[] whiteSpace = reader.Value.ToCharArray();
                        handler.IgnorableWhitespace(whiteSpace, 0, 1);
                        break;

                    case XmlNodeType.Entity:
                        handler.SkippedEntity(reader.Name);
                        break;
                    }
                } //While
                handler.EndDocument();
            }     //try
            catch (Exception exception)
            {
                saxException.LineNumber = reader.LineNumber;
                saxException.SystemID   = "";
                saxException.setMessage(exception.GetBaseException().ToString());
                errorHandler.Error(saxException);
            }
            finally
            {
                if (reader.ReadState != ReadState.Closed)
                {
                    reader.Close();
                }
            }
        } //parse()