public override bool Equals(object ob) { if (ob == this) { return(true); } if (!(ob is DTDNotation)) { return(false); } DTDNotation other = (DTDNotation)ob; if (Name == null) { if (other.Name != null) { return(false); } } else { if (!Name.Equals(other.Name)) { return(false); } } if (ExternalId == null) { if (other.ExternalId != null) { return(false); } } else { if (!ExternalId.Equals(other.ExternalId)) { return(false); } } return(true); }
protected void ParseNotation() { Token token = Expect(Scanner.IDENTIFIER); DTDNotation notation = new DTDNotation(token.Value); Dtd.Notations[notation.Name] = notation; Dtd.Items.Add(notation); token = Expect(Scanner.IDENTIFIER); if (token.Value.Equals("SYSTEM")) { DTDSystem sys = new DTDSystem(); token = Expect(Scanner.STRING); sys.System = token.Value; notation.ExternalId = sys; } else if (token.Value.Equals("PUBLIC")) { DTDPublic pub = new DTDPublic(); token = Expect(Scanner.STRING); pub.Pub = token.Value; pub.System = null; // For <!NOTATION>, you can have PUBLIC PubidLiteral without // a SystemLiteral token = Scanner.Peek(); if (token.Type == Scanner.STRING) { token = Scanner.Get(); pub.System = token.Value; } notation.ExternalId = pub; } Expect(Scanner.GT); }
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 }