Takumi Fujiwara wrote:
> Thanks for your response. But I don't want it to convert, I don't
> want it to create a DOM node either. I just want it to leave it as it
> is.

You can use a filter for this purpose. Here is an
example:

  import org.cyberneko.html.filters.DefaultFilter;

  import org.apache.xerces.util.XMLStringBuffer;
  import org.apache.xerces.xni.Augmentations;
  import org.apache.xerces.xni.XMLLocator;
  import org.apache.xerces.xni.XMLResourceIdentifier;
  import org.apache.xerces.xni.XMLString;
  import org.apache.xerces.xni.XNIException;

  public Entity2Text extends DefaultFilter {

    boolean inEntityRef;
    XMLStringBuffer buffer = new XMLStringBuffer();

    public void startDocument(XMLLocator locator,
                              String encoding,
                              Augmentations augs)
      throws XNIException {
      super.startDocument(locator, encoding, augs);
      inEntityRef = false;
    }

    public void characters(XMLString text,
                           Augmentations augs)
      throws XNIException {
      if (!inEntityRef) {
        super.characters(text, augs);
      }
    }

    public void startGeneralEntity(String name,
                                   XMLResourceIdentifier id,
                                   String encoding,
                                   Augmentations augs)
      throws XNIException {
      inEntityRef = true;
      buffer.clear();
      buffer.append(name);
      super.characters(buffer, augs);
    }

    public void endGeneralEntity(String name,
                                 Augmentations augs)
      throws XNIException {
      inEntityRef = false;
    }

  }

Then you just turn on the notification of entity refs
and append the filter to the parsing pipeline. Like so:

  XMLParserConfiguration config = new HTMLConfiguration();

config.setFeature("http://cyberneko.org/html/features/scanner/notify-builtin-refs";, true);
XMLDocumentFilter[] filters = { new Entity2Text() };
config.setProperty("http://cyberneko.org/html/properties/filters";, filters);


The "setFeature" and "setProperty" methods can also
be called on the parser classes.

Does this work for you?

P.S. I wrote the code by heart so I may have some
     mistakes. But this should get you started.

--
Andy Clark * [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to