Hi Jerome,

Thank you for the very quick response and example. I'll take a closer
look at the JDK javadocs, as you suggest (I've always preferred using
jdom in the past, despite the introduction of a new dependency, so am
not very familiar with the org.w3c.dom api ... but I presume it must be
similar enough :D)

Thanks again,

Chris

Jerome Louvel wrote:
> 
> Hi Christofer,
> 
> Thanks for the short intro and welcome to the list.| Your question is
> more a DOM API related question actually, so I suggest that you have a
> look at the org.w3c.dom.Node interface in the JDK Javadocs and W3C DOM
> specifications.
> 
> To be more concrete, here is something that 'should' work:
> |
> 
> for (Node node : nodeSet)
> {
>    Bookmark bookmark = new Bookmark();
> 
>    Node child = node.getFirstChild();
>    bookmark.setUser(child.getTextContent());
> 
>    child = child.getNextSibling();
>    bookmark.setUrl(child.getTextContent());
> }
> 
> 
> |Best regards,
> Jerome
> |
> Christopher Townson a écrit :
>> Hi,
>>
>> This is my first posting to this list, so I'd like to start by saying
>> I've recently started using Restlet and am really enjoying it - great
>> stuff! However, I have a question to which I can't seem to find a clear
>> answer on Google/docs/O'Reilly Restful Web Services book:
>>
>> I have a DomRepresentation doc which represents a list (of bookmarks in
>> this case) which looks a little like this:
>>
>> <bookmarks>
>>     <bookmark>
>>         <user>Joe Bloggs</user>
>>         <url>http://someplace.com</url>
>>         <tag>foo</tag>
>>         <tag>bar</tag>
>>         ... etc ...
>>     </bookmark>
>>
>>     <bookmark>
>>         ...
>>     </bookmark>
>> </bookmarks>
>>
>> And I have a Bookmark object with properties "user", "url", "tags"
>> (where "tags" is List<String>) and so on.
>>
>> What I need to do is iterate through each bookmark and obtain the text
>> content for each of the relevant nodes to populate an instance of the
>> bookmark object.
>>
>> I'm sure this is totally straightforward, but at the moment I'm at a bit
>> of a loss to find a clear, simple way to do this.
>>
>> My skeleton code so far looks like this:
>>
>> Request request = new Request(Method.GET,
>> "http://www.myserviceendpoint/bookmarks/"; + username);
>> DomRepresentation domRepresentation = new
>> Client(Protocol.HTTP).handle(request).getEntityAsDom();
>> NodeSet nodeSet = domRepresentation.getNodes("/bookmarks/bookmark");
>> // iterate over Nodes and populate Bookmark instance
>> for (Node node : nodeSet)
>> {
>>     Bookmark bookmark = new Bookmark();
>>     // TODO how to get relevant node text?
>>     bookmark.setUser( ... );
>>     bookmark.setUrl( ... );
>> }
>>
>> If anyone could point me in the right direction here, I would be most
>> grateful.
>>
>> It is not really possible here to just use getNodes(expression)
>> repeatedly on the document because, aside from being verbose, each
>> bookmark NodeSet needs to be handled in isolation.
>>
>> Thanks for your help,
>>
>> Chris
>>
>>
>>   
> 

Reply via email to