// --Namespace related (SAX2 Events) public void startPrefixMapping(String prefix, String uri) throws SAXException { AnyNode temp = new AnyNode(AnyNode.NAMESPACE, null, prefix, uri, null); _namespaces.push(temp); if (_processNamespace) { _context = _context.createNamespaces(); _processNamespace = true; } _context.addNamespace(prefix, uri); }
/** Implementation of {@link org.xml.sax.DocumentHandler#startElement} */ public void startElement(String name, AttributeList atts) throws SAXException { _character = false; String qName; String value; AnyNode tempNode = null; // Namespace handling code to be moved once we integrate // the new event API ///////////////// NAMESPACE HANDLING///////////////////// _context = _context.createNamespaces(); String prefix = ""; String namespaceURI = null; int idx = name.indexOf(':'); if (idx >= 0) { prefix = name.substring(0, idx); } namespaceURI = _context.getNamespaceURI(prefix); // --Overhead here since we process attributes twice for (int i = 0; i < atts.getLength(); ++i) { qName = atts.getName(i); value = atts.getValue(i); String nsPrefix = null; if (qName.startsWith(XMLNS_PREFIX)) { // handles namespace declaration // Extract the prefix if any nsPrefix = (qName.equals(XMLNS_PREFIX)) ? null : qName.substring(XMLNS_PREFIX_LENGTH); tempNode = new AnyNode(AnyNode.NAMESPACE, getLocalPart(qName), nsPrefix, value, null); _context.addNamespace(nsPrefix, value); _namespaces.push(tempNode); if (prefix.equals(nsPrefix)) namespaceURI = value; } } //////////////////////// END OF NAMESPACE HANDLING/////////////// createNodeElement(namespaceURI, getLocalPart(name), name); while (!_namespaces.empty()) { tempNode = (AnyNode) _namespaces.pop(); _node.addNamespace(tempNode); } // process attributes for (int i = 0; i < atts.getLength(); ++i) { qName = atts.getName(i); value = atts.getValue(i); // Namespace handling already done if (!qName.startsWith(XMLNS_PREFIX)) { tempNode = new AnyNode(AnyNode.ATTRIBUTE, getLocalPart(qName), null, null, value); _node.addAttribute(tempNode); } } tempNode = null; }
/** Implementation of {@link org.xml.sax.ContentHandler#startElement} */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { AnyNode tempNode; // --SAX2 Parser has not processed the namespaces so we need to do it. if (_processNamespace) { // Namespace handling code to be moved once we integrate // the new event API ///////////////// NAMESPACE HANDLING///////////////////// _context = _context.createNamespaces(); String prefix = ""; int idx = qName.indexOf(':'); if (idx >= 0) { prefix = qName.substring(0, idx); } namespaceURI = _context.getNamespaceURI(prefix); // --Overhead here since we process attributes twice for (int i = 0; i < atts.getLength(); ++i) { String attrqName = atts.getQName(i); String value = atts.getValue(i); String nsPrefix = null; // handles namespace declaration if (attrqName.startsWith(XMLNS_PREFIX)) { // Extract the prefix if any nsPrefix = (attrqName.equals(XMLNS_PREFIX)) ? null : attrqName.substring(XMLNS_PREFIX_LENGTH); tempNode = new AnyNode(AnyNode.NAMESPACE, getLocalPart(attrqName), nsPrefix, value, null); _context.addNamespace(nsPrefix, value); _namespaces.push(tempNode); if (prefix.equals(nsPrefix)) namespaceURI = value; } } //////////////////////// END OF NAMESPACE HANDLING/////////////// } // create element createNodeElement(namespaceURI, localName, qName); // process attributes for (int i = 0; i < atts.getLength(); ++i) { String uri = atts.getURI(i); String attqName = atts.getQName(i); String value = atts.getValue(i); String prefix = null; // -- skip namespace declarations? (handled above) if (_processNamespace) if (attqName.startsWith(XMLNS_PREFIX)) continue; // --attribute namespace prefix? if ((attqName.length() != 0) && (attqName.indexOf(':') != -1)) prefix = attqName.substring(0, attqName.indexOf(':')); // --namespace not yet processed? if (_processNamespace) { // attribute namespace if (prefix != null) uri = _context.getNamespaceURI(prefix); } // --add attribute tempNode = new AnyNode(AnyNode.ATTRIBUTE, getLocalPart(attqName), prefix, uri, value); _node.addAttribute(tempNode); } // --empty the namespace stack and add // --the namespace nodes to the current node. while (!_namespaces.empty()) { tempNode = (AnyNode) _namespaces.pop(); _node.addNamespace(tempNode); } tempNode = null; }
/** * Adds to the namespaces declared in this Schema * @param namespaces the list of namespaces */ public void addNamespace(String prefix, String ns) { _namespaces.addNamespace(prefix, ns); } //-- setNamespaces