net.sf.saxon.om.PrefixNormalizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of saxon9 Show documentation
Show all versions of saxon9 Show documentation
Provides a basic XSLT 2.0 and XQuery 1.0 processor (W3C Recommendations,
January 2007). Command line interfaces and implementations of several
Java APIs (DOM, XPath, s9api) are also included.
The newest version!
package net.sf.saxon.om;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import java.util.HashMap;
import java.util.Stack;
/**
*
*/
public class PrefixNormalizer extends XMLFilterImpl {
private HashMap uriToPrefix = new HashMap(); // contains the preferred prefix for each URI
private Stack prefixes = new Stack();
private Stack uris = new Stack();
/**
* Filter a start Namespace prefix mapping event.
*
* @param prefix The Namespace prefix.
* @param uri The Namespace URI.
* @throws org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
public void startPrefixMapping(String prefix, String uri) throws SAXException {
super.startPrefixMapping(prefix, uri);
prefixes.push(prefix);
uris.push(uri);
if (uriToPrefix.get(uri) == null) {
uriToPrefix.put(uri, prefix);
}
}
/**
* Filter a start element event.
*
* @param uri The element's Namespace URI, or the empty string.
* @param localName The element's local name, or the empty string.
* @param qName The element's qualified (prefixed) name, or the empty
* string.
* @param atts The element's attributes.
* @throws org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
String newQName = qName;
if (uri.length() != 0) {
String preferredPrefix = (String)uriToPrefix.get(uri);
if (!qName.startsWith(preferredPrefix)) {
newQName = preferredPrefix + ':' + localName;
}
}
int alen = atts.getLength();
for (int a=0; a
© 2015 - 2025 Weber Informatics LLC | Privacy Policy