/// <summary> /// Write an empty element. /// This method writes an empty element tag rather than a start tag /// followed by an end tag. Both a <see cref="StartElement" /> /// and an <see cref="EndElement(string,string,string)" /> event will /// be passed on down the filter chain. /// </summary> /// <param name="uri"> /// The element's Namespace URI, or the empty string /// if the element has no Namespace or if Namespace /// processing is not being performed. /// </param> /// <param name="localName"> /// The element's local name (without prefix). This /// parameter must be provided. /// </param> /// <param name="qName"> /// The element's qualified name (with prefix), or /// the empty string if none is available. This parameter /// is strictly advisory: the writer may or may not use /// the prefix attached. /// </param> /// <param name="atts"> /// The element's attribute list. /// </param> /// <exception cref="SAXException"> /// If there is an error /// writing the empty tag, or if a handler further down /// the filter chain raises an exception. /// </exception> /// <seealso cref="StartElement" /> /// <seealso cref="EndElement(string,string,string) " /> public virtual void EmptyElement(string uri, string localName, string qName, IAttributes atts) { _nsSupport.PushContext(); Write('<'); WriteName(uri, localName, qName, true); WriteAttributes(atts); if (_elementLevel == 1) { ForceNSDecls(); } WriteNSDecls(); Write("/>"); base.StartElement(uri, localName, qName, atts); base.EndElement(uri, localName, qName); }
// // 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(); } }
public virtual void Attribute(string aname, string value, bool isSpecified) { // Code changed by MHK 16 April 2001. // The only safe thing to do is to process all the namespace declarations // first, then process the ordinary attributes. So if this is a namespace // declaration, we deal with it now, otherwise we save it till we get the // startElement call. if (_attributeCount++ == 0) { if (_namespaces) { _prefixStack.PushContext(); } } // set nsTemp [0] == namespace URI (or empty) // set nsTemp [1] == local name (or empty) if (value == null) { // MHK: I think this can only happen on an error recovery path // MHK: I was wrong: AElfred was notifying null values of attribute // declared in the DTD as #IMPLIED. But I've now changed it so it doesn't. return; } if (_namespaces && aname.StartsWith("xmlns")) { if (aname.Length == 5) { _prefixStack.DeclarePrefix("", value); //System.err.println("Declare default prefix = "+value); _contentHandler.StartPrefixMapping("", value); } else if (aname[5] == ':' && !aname.Equals("xmlns:xml")) { if (aname.Length == 6) { _errorHandler.Error(new SAXParseException("Missing namespace prefix in namespace declaration: " + aname, this)); return; } string prefix = aname.Substring(6); if (value.Length == 0) { _errorHandler.Error(new SAXParseException("Missing URI in namespace declaration: " + aname, this)); return; } _prefixStack.DeclarePrefix(prefix, value); //System.err.println("Declare prefix " +prefix+"="+value); _contentHandler.StartPrefixMapping(prefix, value); } if (!_xmlNames) { // if xmlNames option wasn't selected, // we don't report xmlns:* declarations as attributes return; } } _attributeNames.Add(aname); _attributeValues.Add(value); }