Hello,

quite strange, I send a sample test code that works for me. Does it work for
you to?

best regards,
Thierry Boileau

        DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory
                .newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory
                .newDocumentBuilder();
        Document document = documentBuilder.newDocument();
        Element rootElement = document.createElement("note");
        document.appendChild(rootElement);
        Element element = document.createElement("from");
        element.appendChild(document.createTextNode("sender"));
        rootElement.appendChild(element);
        element = document.createElement("to");
        element.appendChild(document.createTextNode("recipient"));
        rootElement.appendChild(element);
        element = document.createElement("body");
        element.appendChild(document.createTextNode("hello, you "));
        rootElement.appendChild(element);

        DomRepresentation domRep = new DomRepresentation(
                MediaType.APPLICATION_XML, document);
        System.out.println(domRep.getText());

        Node refNode = domRep.getNode("/note/from/text()");
        if (refNode != null) {
            System.out.println("node " + refNode.getNodeValue());
            System.out.println("node " + refNode.getTextContent());
            System.out.println("node " + refNode.getNodeName());
        } else {
            System.out.println("null");
        }



Thx Fabian for your clue.
>
> Here, I work with local variables for both XML content and XPath value. I
> can print both variable content, even after trying to use the getNode()
> method...
>
> So maybe the truth is out there...
>
>
> > Hello, the post did come twice :-)
> >
> > It's possible that if you print stuff (read: use the stream) from the
> > representation you get in the request body, for example for debug
> > purposes, you'll loose the representation itself (you've already
> > consumed it), so any method accessing it may return null.
> >
> > It's a bit harder to debug streamed representations, but you have to
> > make sure you got all the stream, saved or parsed it somewhere, and
> > only then try to debug it.
> >
> > Hope this helps.
> >
> > On Wed, Dec 29, 2010 at 6:41 AM, Vidrequin <cedric dot vidrequin at gmail
> dot com> wrote:
> > > Hi all,
> > >
> > > this is the first time I post on the mailing list so please apologies
> if some informations are missing: just ask for them and I'll give you them
> with pleasure :)
> > >
> > > ( I also hope I didn't post this message twice -_- )
> > >
> > > I wrote this simple sample of code that should work fine:
> > >
> > > import org.restlet.ext.xml.DomRepresentation;
> > > DomRepresentation domRep = new
> DomRepresentation(MediaType.APPLICATION_XML, doc.getDom());
> > > refNode = domRep.getNode(refnode);
> > >
> > > Here, doc.getDom() is a valid XML Document (org.w3c.dom.Document) : I
> print the content of the document as a String (in the console) and the
> content is ok.
> > > I also use the org.restlet.data.MediaType.
> > >
> > > I try to search for the following xpath :
> "/section/section/section/para/text()" but it fails : the method getNode()
> returns null.
> > > I checked the content of the XML and the path exists.
> > >
> > > I tried with simpler xpath, like "/section" but it returns null too.
> > > When I print the result of getNode("/*"), it shows "[section: null]".
> > > When I print the result of getNode("/"), it shows "[#document: null]".
> > >
> > > Does any one know what is the reason of this problem ? or what could I
> do to solve it ?
> > > Do you need more informations ?
> > >
> > > Thanks in advance for helping.
> > >
> > > ------------------------------------------------------
> > >
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2694560
> > >
> >
> >
> >
> > --
> > Fabián Mandelbaum
> > IS Engineer
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2694977
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2697624

Reply via email to