} }  String xmlId = element.getAttribute("xml:id"); if (xmlId == null) { xmlId = element.getAttributeNS(XMLConstants.XML_NS_URI, "id"); } if (id.equals(xmlId)) { return element;
  public Element getElementById(String id)  {    DomDoctype doctype = (DomDoctype) getDoctype();        if (doctype == null || !doctype.hasIds()        || id == null || id.length() == 0)      {        return null;      }        // yes, this is linear in size of document.    // it'd be easy enough to maintain a hashtable.    Node current = getDocumentElement();    Node temp;        if (current == null)      {        return null;      }    while (current != this)      {        // done?        if (current.getNodeType() == ELEMENT_NODE)          {            DomElement element = (DomElement) current;            DTDElementTypeInfo info =              doctype.getElementTypeInfo(current.getNodeName());            if (info != null &&                id.equals(element.getAttribute(info.idAttrName)))              {                return element;              }            else if (element.userIdAttrs != null)              {                for (Iterator i = element.userIdAttrs.iterator();                     i.hasNext(); )                  {                    Node idAttr = (Node) i.next();                    if (id.equals(idAttr.getNodeValue()))                      {                        return element;                      }                  }              }          }                // descend?        if (current.hasChildNodes())          {            current = current.getFirstChild();            continue;          }                // lateral?        temp = current.getNextSibling();        if (temp != null)          {            current = temp;            continue;          }                // back up ...         do          {            temp = current.getParentNode();            if (temp == null)              {                return null;              }            current = temp;            temp = current.getNextSibling();          }        while (temp == null);        current = temp;      }    return null;  }