Hi John,

I send you a sample test code that works correctly.
I hope it will help you. Otherwise, could you send us a reproductible test code?

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org <http://www.restlet.org/>
Noelios Technologies ~ Co-founder ~ http://www.noelios.com <http://www.noelios.com/>


Hey, again, all.

I'm trying to use an XPath expression to get a NodeSet. This ought to be really straightforward, based on the sample code I've seen, but I'm having some troubles. I've verified that my response contains a valid XHTML entity.

DomRepresentation doc = response.getEntityAsDom();
String xpath = "//a";
NodeSet nodes = doc.getNodes(xpath);  //This returns null

I've traced in enough to see that the InputStream inside the DomRepresentation is null - XmlRepresentation.internalEval() is catching the InvalidArgumentException that gets thrown by DocumentBuildre.parse().

Is there some step I'm missing here?

Thanks for any help!

(I'm running Restlet 1.1 RC1, JDK 1.6.0_06, in Eclipse 3.3.2, on Windows Vista.)

--------------------------------
John Wismar
[EMAIL PROTECTED]

package testDomRepresentation;

import org.restlet.Application;
import org.restlet.Client;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.Router;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.DomRepresentation;
import org.restlet.resource.StringRepresentation;
import org.restlet.util.NodeSet;

public class TestApplication extends Application {
    public static void main(String[] args) throws Exception {
        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8182);
        component.getDefaultHost().attachDefault(new TestApplication());

        component.start();

        Client client = new Client(Protocol.HTTP);
        Response response = client.get("http://localhost:8182/";);
        DomRepresentation doc = response.getEntityAsDom();
        String xpath = "//a";
        NodeSet nodes = doc.getNodes(xpath); // This returns null
        System.out.println(nodes.get(0).getTextContent());
        component.stop();

    }

    @Override
    public Restlet createRoot() {
        Router router = new Router(getContext());

        Restlet restlet = new Restlet() {

            @Override
            public void handle(Request request, Response response) {
                response.setEntity(new StringRepresentation("<a>b</a>",
                        MediaType.TEXT_XML));
            }

        };
        router.attachDefault(restlet);
        return router;
    }

}

Reply via email to