Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Re: Java and parsing XHTML (luca)

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: luca <passani AT eunet.no>
  • To: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Re: Java and parsing XHTML (luca)
  • Date: Sat, 11 Sep 2004 21:23:19 +0200



Elliotte Harold wrote:

You're proposed solution seems correct. But it may be easier to just not to override makeAttribute at all. It might be slower, but it might not be noticeable. It would certainly be simpler

well, this has to go into a Servlet filter which parses each response
from a JSP page (or whatever else), so avoiding
the traversal of the tree when all I need is to collect the
image URLs is highly desirable....or maybe I misunderstood what
you were trying to say?
So far, I am testing the single pieces one by one.

here is the subclass of NodeFactory that makes me retrieve
the URLs:


class StreamingImgLister extends NodeFactory{

private int depth = 0;
private Nodes empty = new Nodes();
public ArrayList urls = new ArrayList(20);

// We don't need the comments.
public Nodes makeComment(String data) {
return empty;
}

// We don't need text nodes at all
public Nodes makeText(String data) {
return empty;
}

public Element startMakingElement(String name, String namespace) {
//add to Elem List
//if (name.equals("img") ) {
// urls.add(name);
//}
return new Element(name, namespace);
}

public Nodes finishMakingElement(Element element) {

if (element.getLocalName().equals("img")) {
System.out.println(element.toXML());
if (element.getAttributeValue("src") != null) {
urls.add(element.getAttributeValue("src"));
}
}
if (element.getParent() instanceof Document) {
return new Nodes(element);
}
else return empty;
}

public Nodes makeAttribute(String name, String URI,
String value, Attribute.Type type) {
if (name.equals("src") ) {
return new Nodes(new Attribute(name, URI, value, type));
}
return empty;
}

public Nodes makeDocType(String rootElementName,
String publicID, String systemID) {
return empty;
}

public Nodes makeProcessingInstruction(
String target, String data) {
return empty;
}

}


BTW, is there a way for XOM to retrieve a picture through
HTTP and save it into some binary buffer?
a previous msg of yours seemed to imply this...

Luca






Archive powered by MHonArc 2.6.24.

Top of Page