Exemple #1
0
 /// <summary>
 ///     Internal initialization method.
 ///     <para>All of the public constructors invoke this method.</para>
 /// </summary>
 /// <param name="writer">
 ///     The output destination, or null to use
 ///     standard output.
 /// </param>
 private void Init(TextWriter writer)
 {
     SetOutput(writer);
     _nsSupport = new NamespaceSupport();
     _prefixTable = new Hashtable();
     _forcedDeclTable = new Hashtable();
     _doneDeclTable = new Hashtable();
     _outputProperties = ConfigurationManager.AppSettings;
 }
        /*
         * <b>Sax1, Sax2</b>: Auxiliary API to parse an Xml document, used mostly
         * when no URI is available.
         * If you want anything useful to happen, you should set
         * at least one type of handler.
         * @param source The Xml input source.  Don't set 'encoding' unless
         *  you know for a fact that it's correct.
         * @see #setEntityResolver
         * @see #setDtdHandler
         * @see #setContentHandler
         * @see #setErrorHandler
         * @exception SaxException The handlers may throw any SaxException,
         *  and the parser normally throws SaxParseException objects.
         * @exception IOException IOExceptions are normally through through
         *  the parser if there are problems reading the source document.
         */
        public void Parse(InputSource source)
        {
            //FIXME!! synchronized(base) {
            parser = new XmlParser();
            if (namespaces)
            {
                namespaceSupport = new NamespaceSupport();
                namespaceSupport.NamespaceDeclUris = true;
            }
            parser.setHandler(this);

            try {
                // .NET
                status = XmlReaderStatus.Parsing;
                Stream     stream = null;
                TextReader reader = null;
                if (source is InputSource <Stream> )
                {
                    stream = ((InputSource <Stream>)source).Source;
                }
                if (source is InputSource <TextReader> )
                {
                    reader = ((InputSource <TextReader>)source).Source;
                }
                if (source.SystemId == null && stream != null)
                {
                    if (stream is FileStream)
                    {
                        source.SystemId = ((FileStream)stream).Name;
                    }
                }
                parser.doParse(source.SystemId,
                               source.PublicId,
                               reader,
                               stream,
                               source.Encoding);
            } catch (SaxException e) {
                throw e;
            } catch (Exception e) {
                throw new SaxParseException(new ParseErrorImpl(e.Message, this, e));
            } finally {
                contentHandler.EndDocument();
                entityStack.Clear();
                parser           = null;
                namespaceSupport = null;
                status           = XmlReaderStatus.Ready;
            }
        }
Exemple #3
0
 /// <summary>
 ///     Internal initialization method.
 ///     <para>All of the public constructors invoke this method.</para>
 /// </summary>
 /// <param name="writer">
 ///     The output destination, or null to use
 ///     standard output.
 /// </param>
 private void Init(TextWriter writer) {
   SetOutput(writer);
   _nsSupport = new NamespaceSupport();
   _prefixTable = new Hashtable();
   _forcedDeclTable = new Hashtable();
   _doneDeclTable = new Hashtable();
   _outputProperties = ConfigurationManager.AppSettings;
 }