for (Node child = entity.getFirstChild(); child != null; child = child.getNextSibling())
Node child = ref.getFirstChild(); while (child != null)
  public void endEntity(String name)    throws SAXException  {    if ("[dtd]".equals(name) || name.charAt(0) == '%')      {        // Ignore DTD and parameter entities        return;      }    if ("lt".equals(name) ||        "gt".equals(name) ||        "amp".equals(name) ||        "apos".equals(name) ||        "quot".equals(name))      {        return;      }    // Get entity    Entity entity = popEntity();    // TODO resolve external entities to ensure that entity has content    if (expandEntityReferences)      {        // Get entity content        for (Node child = entity.getFirstChild(); child != null;             child = child.getNextSibling())          {            ctx.appendChild(child);          }      }    else      {        Node entityReference = doc.createEntityReference(name);        ctx.appendChild(entityReference);      }  }