Пример #1
0
 public virtual void StartDocument()
 {
     _contentHandler.SetDocumentLocator(this);
     _contentHandler.StartDocument();
     _attributeNames.Clear();
     _attributeValues.Clear();
 }
Пример #2
0
 public virtual void StartDocument()
 {
     if (_contentHandler != null)
     {
         _contentHandler.StartDocument();
     }
 }
Пример #3
0
        //
        // This is where the driver receives XmlParser callbacks and translates
        // them into Sax callbacks.  Some more callbacks have been added for
        // Sax2 support.
        //

        internal void startDocument()
        {
            contentHandler.SetDocumentLocator(this);
            contentHandler.StartDocument();
            if (namespaces)
            {
                namespaceSupport.Reset();
                namespaceSupport.PushContext();
            }
            attributeCount = 0;
            attributes     = false;
            for (int i = attributeCount; i < attributeData.Length; i++)
            {
                attributeData[i] = new AttributeData();
            }
        }
Пример #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()