Hi Everyone,

i haven't found a bug report for this so i thought i ask here

please considered the following snippet:

public static void main(String[] args) {
        Abdera abdera = new Abdera();
        AbderaClient client = new AbderaClient(abdera);
ClientResponse resp = client.get("http://mail-archives.apache.org/mod_mbox/incubator-abdera-dev/?format=atom";);
        if (resp.getType() == ResponseType.SUCCESS) {
          Document<Feed> doc = resp.getDocument();
System.out.println(doc.getRoot().getEntries().iterator().next().getContent());
        } else {
        }
}


Right at the end of the content i get an empty </> xml tag.
Something like this:

<pre>My content</pre> </>



I dived through the code and found the <org.apache.abdera.parser.stax.FOMDiv>.getInternalValue() Class which I think is supposed to handle this:

  protected String getInternalValue() {
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      XMLStreamWriter writer =
        XMLOutputFactory.newInstance().createXMLStreamWriter(out);
      writer.writeStartElement("");
      for (Iterator nodes = this.getChildren(); nodes.hasNext();) {
        OMNode node = (OMNode) nodes.next();
        node.serialize(writer);
      }
      writer.writeEndElement();
      return out.toString().substring(2);
    } catch (Exception e) {}
    return "";
  }

If I understand that right abdera is trying to remove the surrounding "div" tag. Unfortunately the output from this method cannot be used if you need valid xhtml or at least valid xml because of the empty element tag.

I shudder when i see
out.toString().substring(2);

For now i decided to stick with abdera, but handle the xhtml myself:

Element c = doc.getRoot().getEntries().iterator().next().getContentElement().getFirstChild();
try {
  StringWriter out = new StringWriter();
  Element e = c.getFirstChild();
  while (e != null) {
          e.writeTo(out);
          e = e.getNextSibling();
  }
  System.out.println(out.toString());
} catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
}


Would be nice to know whether this is some kind of bug, or whether i got something wrong.

g
christoph bauer



Reply via email to