String newId = URLEncoder.encode(id); newId = avoidConflicts(doc, sect, this.idAttr, newId);
String newId; try { newId = URLEncoder.encode(id, "UTF-8"); } catch( java.io.UnsupportedEncodingException e ) { getLogger().error("cannot encode Id, using generate-id instead...", e); newId = processor.evaluateAsString(sect, "generate-id()"); } newId = avoidConflicts(doc, sect, this.idAttr, newId);
    private Document addIds(Document doc, String elementXPath, String idXPath) throws SAXException {        getLogger().debug("## Using element XPath "+elementXPath);        NodeList sects = processor.selectNodeList(doc, elementXPath);        getLogger().debug("## .. got "+sects.getLength()+" sections");        for (int i=0; i<sects.getLength(); i++) {            Element sect = (Element)sects.item(i);            if (!sect.hasAttribute(this.idAttr)) {                sect.normalize();                getLogger().debug("## Using id XPath "+idXPath);                String id = null;                try {                  id = processor.evaluateAsString(sect, idXPath).trim();                } catch (Exception e) {                    throw new SAXException("'id' XPath expression '"+idXPath+"' does not return a text node: "+e, e);                }                getLogger().info("## Got id "+id);                //FIXME: + produces an error on document schema                String newId = URLEncoder.encode(id);                newId = avoidConflicts(doc, sect, this.idAttr, newId);                // Upgrade to DOM 2 support                //sect.setAttribute(this.idAttr, newId);                sect.setAttributeNS(sect.getNamespaceURI(), this.idAttr, newId);            }        }        return doc;    }