/// <summary> /// Assigns the specified property. Like SAX1 handlers, /// these may be changed at any time. /// </summary> public virtual void SetProperty(string propertyId, object property) { try { // Properties with a defined value, we just change it if we can. GetProperty(propertyId); if ((HANDLER + "declaration-handler").Equals(propertyId)) { if (property == null) { _declHandler = _base; } else if (!(property is IDeclHandler)) { throw new SAXNotSupportedException(propertyId); } else { _declHandler = (IDeclHandler)property; } return; } if ((HANDLER + "lexical-handler").Equals(propertyId) || "http://xml.org/sax/handlers/LexicalHandler".Equals(propertyId)) { // the latter name is used in some SAX2 beta software if (property == null) { _lexicalHandler = _base; } else if (!(property is ILexicalHandler)) { throw new SAXNotSupportedException(propertyId); } else { _lexicalHandler = (ILexicalHandler)property; } return; } // can't change builtins if (_properties == null || !_properties.ContainsKey(propertyId)) { throw new SAXNotSupportedException(propertyId); } } catch (SAXNotRecognizedException e) { // as-yet unknown properties if (_properties == null) { _properties = new Hashtable(5); } } // record first value, or modify existing one _properties.Add(propertyId, property); }
/// <summary> /// Constructs a SAX Parser. /// </summary> public SAXDriver() { _entityResolver = _base; _contentHandler = _base; _dtdHandler = _base; _errorHandler = _base; _declHandler = _base; _lexicalHandler = _base; }
public void SetProperty(string name, object value) { if (name.Equals(LEXICAL_HANDLER_PROPERTY)) { if (value == null) { _lexicalHandler = this; } else { var handler = value as ILexicalHandler; if (handler != null) { _lexicalHandler = handler; } else { throw new SAXNotSupportedException("Your lexical handler is not a ILexicalHandler"); } } } else if (name.Equals(SCANNER_PROPERTY)) { var scanner = value as IScanner; if (scanner != null) { _scanner = scanner; } else { throw new SAXNotSupportedException("Your scanner is not a IScanner"); } } else if (name.Equals(SCHEMA_PROPERTY)) { var schema = value as Schema; if (schema != null) { _schema = schema; } else { throw new SAXNotSupportedException("Your schema is not a Schema"); } } else if (name.Equals(AUTO_DETECTOR_PROPERTY)) { var detector = value as IAutoDetector; if (detector != null) { _autoDetector = detector; } else { throw new SAXNotSupportedException("Your auto-detector is not an IAutoDetector"); } } else { throw new SAXNotRecognizedException("Unknown property " + name); } }
/// <summary> /// Creates a new instance of <see cref="Parser" /> /// </summary> public Parser() { _newElement = null; _contentHandler = this; _lexicalHandler = this; _dtdHandler = this; _errorHandler = this; _entityResolver = this; }
/// <summary> /// Assigns the specified property. Like SAX1 handlers, /// these may be changed at any time. /// </summary> public virtual void SetProperty(string propertyId, object property) { try { // Properties with a defined value, we just change it if we can. GetProperty(propertyId); if ((HANDLER + "declaration-handler").Equals(propertyId)) { if (property == null) { _declHandler = _base; } else if (! (property is IDeclHandler)) { throw new SAXNotSupportedException(propertyId); } else { _declHandler = (IDeclHandler)property; } return; } if ((HANDLER + "lexical-handler").Equals(propertyId) || "http://xml.org/sax/handlers/LexicalHandler".Equals(propertyId)) { // the latter name is used in some SAX2 beta software if (property == null) { _lexicalHandler = _base; } else if (! (property is ILexicalHandler)) { throw new SAXNotSupportedException(propertyId); } else { _lexicalHandler = (ILexicalHandler)property; } return; } // can't change builtins if (_properties == null || !_properties.ContainsKey(propertyId)) { throw new SAXNotSupportedException(propertyId); } } catch (SAXNotRecognizedException e) { // as-yet unknown properties if (_properties == null) { _properties = new Hashtable(5); } } // record first value, or modify existing one _properties.Add(propertyId, property); }