コード例 #1
0
 /** Creates a parser that will read from the specified filename
  * @param filename The file to read
  * @param trace True if the parser should print out tokens as it reads them
  *  (used for debugging the parser)
  */
 public DTDParser(string filename, bool trace)
 {
     if (!File.Exists(filename))
     {
         throw new DTDParseException(string.Format("File not found: {0}", filename));
     }
     DefaultLocation = Directory.GetParent(filename);
     Scanner         = new Scanner(new StreamReader(filename), trace, this);
     Dtd             = new DTD();
 }
コード例 #2
0
 protected void RemoveElements(Hashtable h, DTD dtd, DTDItem item)
 {
     if (item is DTDName)
     {
         h.Remove(((DTDName)item).Value);
     }
     else if (item is DTDContainer)
     {
         foreach (DTDItem dtditem in ((DTDContainer)item).Items)
         {
             RemoveElements(h, dtd, dtditem);
         }
     }
 }
コード例 #3
0
ファイル: DTD.cs プロジェクト: ARLM-Keller/Daisy-Tobi-App
        /** Returns true if this object is equal to another */
        public override bool Equals(object ob)
        {
            if (this == ob)
            {
                return(true);
            }

            if (!(ob is DTD))
            {
                return(false);
            }

            DTD otherDTD = (DTD)ob;

            return(Items.Equals(otherDTD.Items));
        }
コード例 #4
0
        /** Creates a parser that will read from the specified URL object
         * @param uri The URL to read
         * @param trace True if the parser should print out tokens as it reads them
         *  (used for debugging the parser)
         */
        public DTDParser(Uri uri, bool trace)
        {
            //LAM: we need to set the defaultLocation to the directory where
            //the dtd is found so that we don't run into problems parsing any
            //relative external files referenced by the dtd.
            string file = uri.ToString();

            DefaultLocation = file.Substring(0, file.LastIndexOf(Environment.NewLine) + 1);

            WebRequest   req    = WebRequest.Create(uri);
            WebResponse  resp   = req.GetResponse();
            Stream       stream = resp.GetResponseStream();
            StreamReader sr     = new StreamReader(stream);

            Scanner = new Scanner(sr, trace, this);
            Dtd     = new DTD();
        }
コード例 #5
0
        public static void TestParseDtd(string file, bool writeToLog)
        {
            try
            {
                DTDParser parser = null;
                // MAW Version 1.17
                // If it looks like the filename may be a URL, use the URL class
                if (file.IndexOf("://") > 0)
                {
                    parser = new DTDParser(new Uri(file), true);
                }
                else
                {
                    parser = new DTDParser(file, true);
                }


                // Parse the DTD and ask the parser to guess the root element
                DTD dtd = parser.Parse(true);

                FileStream   ostrm  = null;
                StreamWriter writer = null;
                TextWriter   oldOut = null;

                if (writeToLog)
                {
                    oldOut = Console.Out;
                    ostrm  = new FileStream("./log.txt", FileMode.OpenOrCreate, FileAccess.Write);
                    writer = new StreamWriter(ostrm);
                    Console.SetOut(writer);
                }
                if (dtd.RootElement != null)
                {
                    Console.WriteLine("Root element is probably: " +
                                      dtd.RootElement.Name);
                }

                foreach (DictionaryEntry de in dtd.Elements)
                {
                    DTDElement elem = (DTDElement)de.Value;

                    Console.WriteLine("Element: " + elem.Name);
                    Console.Write("   Content: ");
                    DumpDtdItem(elem.Content);
                    Console.WriteLine();

                    if (elem.Attributes.Count > 0)
                    {
                        Console.WriteLine("   Attributes: ");
                        foreach (DictionaryEntry attr_de in elem.Attributes)
                        {
                            Console.Write("        ");
                            DTDAttribute attr = (DTDAttribute)attr_de.Value;
                            DumpAttribute(attr);
                        }
                        Console.WriteLine();
                    }
                }


                foreach (DictionaryEntry de in dtd.Entities)
                {
                    DTDEntity entity = (DTDEntity)de.Value;

                    if (entity.IsParsed)
                    {
                        Console.Write("Parsed ");
                    }

                    Console.WriteLine("Entity: " + entity.Name);

                    if (entity.Value != null)
                    {
                        Console.WriteLine("    Value: " + entity.Value);
                    }

                    if (entity.ExternalId != null)
                    {
                        if (entity.ExternalId is DTDSystem)
                        {
                            Console.WriteLine("    System: " + entity.ExternalId.System);
                        }
                        else
                        {
                            DTDPublic pub = (DTDPublic)entity.ExternalId;
                            Console.WriteLine("    Public: " + pub.Pub + " " + pub.System);
                        }
                    }

                    if (entity.Ndata != null)
                    {
                        Console.WriteLine("    NDATA " + entity.Ndata);
                    }
                }
                foreach (DictionaryEntry de in dtd.Notations)
                {
                    DTDNotation notation = (DTDNotation)de.Value;

                    Console.WriteLine("Notation: " + notation.Name);

                    if (notation.ExternalId != null)
                    {
                        if (notation.ExternalId is DTDSystem)
                        {
                            Console.WriteLine("    System: " +
                                              notation.ExternalId.System);
                        }
                        else
                        {
                            DTDPublic pub = (DTDPublic)notation.ExternalId;

                            Console.Write("    Public: " +
                                          pub.Pub + " ");
                            if (pub.System != null)
                            {
                                Console.WriteLine(pub.System);
                            }
                            else
                            {
                                Console.WriteLine();
                            }
                        }
                    }
                }
                if (writeToLog)
                {
                    Console.SetOut(oldOut);
                    writer.Close();
                    ostrm.Close();
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc.StackTrace);
                Console.WriteLine(exc.Message);
            }


            Console.WriteLine("Done");
            Console.ReadKey(); //keep the console open
        }
コード例 #6
0
 /** Creates a parser that will read from the specified Reader object
  * @param in The input stream to read
  * @param trace True if the parser should print out tokens as it reads them
  *  (used for debugging the parser)
  */
 public DTDParser(StreamReader reader, bool trace)
 {
     Scanner = new Scanner(reader, trace, this);
     Dtd     = new DTD();
 }
コード例 #7
0
 /** Creates a parser that will read from the specified Reader object */
 public DTDParser(StreamReader reader)
 {
     Scanner = new Scanner(reader, false, this);
     Dtd     = new DTD();
 }