Attr attrib = doc.createAttributeNS(namespace, name);
Attr attrib = namespace != null && namespace.length() > 0 ? doc.createAttributeNS(namespace, name) : doc.createAttribute(name);
	public void startElement(		String namespaceURI,		String localName,		String qName,		Attributes atts)		throws SAXException {		// save accumulated character content		if (inModification && charBuf.length() > 0) {			final String normalized = preserveWhitespace ? charBuf.toString() :				charBuf.getNormalizedString(FastStringBuffer.SUPPRESS_BOTH);			if (normalized.length() > 0) {				Text text = doc.createTextNode(normalized);				if (stack.isEmpty()) {					//LOG.debug("appending text to fragment: " + text.getData());					contents.add(text);				} else {					Element last = (Element) stack.peek();					last.appendChild(text);				}			}			charBuf.setLength(0);		}		if (namespaceURI.equals(XUPDATE_NS)) {			String select = null;			if (localName.equals(MODIFICATIONS)) {				startModifications(atts);				return;			} else if (localName.equals(VARIABLE)) {				// variable declaration				startVariableDecl(atts);				return;			} else if (IF.equals(localName)) {				if (inModification)					throw new SAXException("xupdate:if is not allowed inside a modification");				select = atts.getValue("test");				Conditional cond = new Conditional(broker, documentSet, select, namespaces, variables);				conditionals.push(cond);				return;			} else if (VALUE_OF.equals(localName)) {				if(!inModification)					throw new SAXException("xupdate:value-of is not allowed outside a modification");							} else if (APPEND.equals(localName)				|| INSERT_BEFORE.equals(localName)				|| INSERT_AFTER.equals(localName)				|| REMOVE.equals(localName)				|| RENAME.equals(localName)				|| UPDATE.equals(localName)				|| REPLACE.equals(localName)) {				if (inModification)					throw new SAXException("nested modifications are not allowed");				select = atts.getValue("select");				if (select == null)					throw new SAXException(						localName + " requires a select attribute");				doc = builder.newDocument();				contents = new NodeListImpl();				inModification = true;			} else if (				(ELEMENT.equals(localName)					|| ATTRIBUTE.equals(localName)					|| TEXT.equals(localName)					|| PROCESSING_INSTRUCTION.equals(localName)					|| COMMENT.equals(localName))) {				if(!inModification)					throw new SAXException(							"creation elements are only allowed inside "							+ "a modification");				charBuf.setLength(0);			} else				throw new SAXException("Unknown XUpdate element: " + qName);			// start a new modification section			if (APPEND.equals(localName)) {			    String child = atts.getValue("child");				modification = new Append(broker, documentSet, select, child, namespaces, variables);			} else if (UPDATE.equals(localName))				modification = new Update(broker, documentSet, select, namespaces, variables);			else if (INSERT_BEFORE.equals(localName))				modification =					new Insert(broker, documentSet, select, Insert.INSERT_BEFORE, namespaces, variables);			else if (INSERT_AFTER.equals(localName))				modification =					new Insert(broker, documentSet, select, Insert.INSERT_AFTER, namespaces, variables);			else if (REMOVE.equals(localName))				modification = new Remove(broker, documentSet, select, namespaces, variables);			else if (RENAME.equals(localName))				modification = new Rename(broker, documentSet, select, namespaces, variables);			else if (REPLACE.equals(localName))				modification = new Replace(broker, documentSet, select, namespaces, variables);			// process commands for node creation			else if (ELEMENT.equals(localName)) {				String name = atts.getValue("name");				if (name == null)					throw new SAXException("element requires a name attribute");				int p = name.indexOf(':');				String namespace = "";				String prefix = "";				if (p > -1) {					prefix = name.substring(0, p);					if (name.length() == p + 1)						throw new SAXException(							"illegal prefix in qname: " + name);					name = name.substring(p + 1);					namespace = atts.getValue("namespace");					if(namespace == null)						namespace = (String) namespaces.get(prefix);					if (namespace == null) {						throw new SAXException(							"no namespace defined for prefix " + prefix);					}				}				Element elem = doc.createElementNS(namespace, name);				elem.setPrefix(prefix);				if (stack.isEmpty()) {					contents.add(elem);				} else {					Element last = (Element) stack.peek();					last.appendChild(elem);				}				this.setWhitespaceHandling((Element) stack.push(elem));			} else if (ATTRIBUTE.equals(localName)) {				String name = atts.getValue("name");				if (name == null)					throw new SAXException("attribute requires a name attribute");				int p = name.indexOf(':');				String namespace = "";				if (p > -1) {					String prefix = name.substring(0, p);					if (name.length() == p + 1)						throw new SAXException(							"illegal prefix in qname: " + name);					namespace = atts.getValue("namespace");					if(namespace == null)						namespace = (String) namespaces.get(prefix);					if (namespace == null)						throw new SAXException(							"no namespace defined for prefix " + prefix);				}				Attr attrib = doc.createAttributeNS(namespace, name);				if (stack.isEmpty()) {					for(int i = 0; i < contents.getLength(); i++) {						Node n = contents.item(i);						String ns = n.getNamespaceURI();						if(ns == null) ns = "";						if(n.getNodeType() == Node.ATTRIBUTE_NODE &&								n.getLocalName().equals(name) &&								ns.equals(namespace))							throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified twice");					}					contents.add(attrib);				} else {					Element last = (Element) stack.peek();					if(last.hasAttributeNS(namespace, name))						throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified " +								"twice on the same element");					last.setAttributeNodeNS(attrib);				}				inAttribute = true;				currentNode = attrib;				// process value-of			} else if (VALUE_OF.equals(localName)) {				select = atts.getValue("select");				if (select == null)					throw new SAXException("value-of requires a select attribute");				Sequence seq = processQuery(select);				LOG.debug("Found " + seq.getLength() + " items for value-of");				Item item;				for (SequenceIterator i = seq.iterate(); i.hasNext();) {					item = i.nextItem();					if(Type.subTypeOf(item.getType(), Type.NODE)) { 						Node node = XMLUtil.copyNode(doc, ((NodeValue)item).getNode());						if (stack.isEmpty())							contents.add(node);						else {							Element last = (Element) stack.peek();							last.appendChild(node);						}					} else {						try {							String value = item.getStringValue();							characters(value.toCharArray(), 0, value.length());						} catch(XPathException e) {							throw new SAXException(e.getMessage(), e);						}					}				}			}		} else if (inModification) {			Element elem = doc.createElementNS(namespaceURI, qName);			Attr a;			for (int i = 0; i < atts.getLength(); i++) {                String name = atts.getQName(i);                String nsURI = atts.getURI(i);                if (name.startsWith("xmlns")) {                    // Why are these showing up? They are supposed to be stripped out?                } else {                    a = doc.createAttributeNS(nsURI, name);                    a.setValue(atts.getValue(i));                    elem.setAttributeNodeNS(a);                }			}			if (stack.isEmpty()) {				contents.add(elem);			} else {				Element last = (Element) stack.peek();				last.appendChild(elem);			}            this.setWhitespaceHandling((Element) stack.push(elem));		}	}