RE: Version 2: How to get XML representation

2011-08-27 Thread Jerome Louvel
Hi again,

I have just completed the user guide to explain more the client-side usage of 
the ConverterService via ClientResource:
http://wiki.restlet.org/docs_2.1/360-restlet

Hope this helps,
Jerome

-Message d'origine-
De : Jerome Louvel [mailto:jerome.lou...@noelios.com] 
Envoyé : samedi 27 août 2011 01:02
À : 'discuss'
Objet : RE: Version 2: How to get XML representation

Hi Alex,

Definitely, the user guide is scarce in some areas... Currently, we try to 
finish the Restlet in Action book which goes into more details with examples 
about such features. Then, in v 2.2 we'll continue expanding the documentation 
progressively, but would welcome contributions to the user guide from serious 
writers that want to contribute back in this way.

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg Noelios 
Technologies ~ http://www.noelios.com




-Message d'origine-
De : ale...@milowski.com [mailto:ale...@milowski.com] De la part de Alex 
Milowski Envoyé : vendredi 26 août 2011 21:28 À : discuss@restlet.tigris.org 
Objet : Re: Version 2: How to get XML representation

On Fri, Aug 26, 2011 at 1:05 AM, Jerome Louvel jerome.lou...@noelios.com 
wrote:
 Hi Ivano,

 Another option would be to do:

Document doc = resource.get(Document.class);

 That should just works with automagic conversion :)


That is some magic!  I just took a look at this page on the ConverterService:

   
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/331-restlet/360-restlet.html

I'm left wanting a bit more of an example other than digging into the source.  
Neat idea thought and I may have to try this out for my own classes.

--Alex Milowski

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

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


RE: Version 2: How to get XML representation

2011-08-26 Thread Jerome Louvel
Hi Ivano,

Another option would be to do: 

Document doc = resource.get(Document.class);

That should just works with automagic conversion :)

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg
Noelios Technologies ~ http://www.noelios.com



-Message d'origine-
De : ale...@milowski.com [mailto:ale...@milowski.com] De la part de Alex 
Milowski
Envoyé : jeudi 25 août 2011 20:26
À : discuss@restlet.tigris.org
Objet : Re: Version 2: How to get XML representation

On Thu, Aug 25, 2011 at 10:10 AM, Ivano Carrara icarr...@studio5.it wrote:
 Hi all,

 Using Version 1 of Restlet, I built a client to get Xml from a remote server 
 and to examine it using Xpath expressions - below a fragment of code:

 Request req = new Request(Method.GET, url); Client client = new 
 Client(Protocol.HTTP); Response resp = client.handle(req);

 DomRepresentation doc = resp.getEntityAsDom();

 How I can obtain the same doc object using the Version 2 ?

 Below the actual code:

 ClientResource resource = new ClientResource(url); resource.get();

 Then using resource.get().getText()); I obtain the text of my XML, but I 
 need the DOM representation to use with XPath expressions.

 With Version 2, what is the equivalent code to DomRepresentation doc = 
 resp.getEntityAsDom(); of Version 1 ?

You can either use the DocumentBuilder API from JAXP:

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  docBuilder = factory.newDocumentBuilder();
  Document doc = docBuilder.parse(new 
InputSource(resource.get().getReader()));

or you can use the DomRepresentation from the XML extension:

 DomRepresentation domRep = new DomRepresentation(resource.get());
 Document doc = domRep.getDocument();

I personally use the DocumentBuilder API so I have control over the DOM 
construction.

--Alex Milowski

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

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


Re: Version 2: How to get XML representation

2011-08-26 Thread Alex Milowski
On Fri, Aug 26, 2011 at 1:05 AM, Jerome Louvel
jerome.lou...@noelios.com wrote:
 Hi Ivano,

 Another option would be to do:

        Document doc = resource.get(Document.class);

 That should just works with automagic conversion :)


That is some magic!  I just took a look at this page on the ConverterService:

   
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/331-restlet/360-restlet.html

I'm left wanting a bit more of an example other than digging into the
source.  Neat idea thought and I may have to try this out for my own
classes.

--Alex Milowski

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


RE: Version 2: How to get XML representation

2011-08-26 Thread Jerome Louvel
Hi Alex,

Definitely, the user guide is scarce in some areas... Currently, we try to 
finish the Restlet in Action book which goes into more details with examples 
about such features. Then, in v 2.2 we'll continue expanding the documentation 
progressively, but would welcome contributions to the user guide from serious 
writers that want to contribute back in this way.

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg
Noelios Technologies ~ http://www.noelios.com




-Message d'origine-
De : ale...@milowski.com [mailto:ale...@milowski.com] De la part de Alex 
Milowski
Envoyé : vendredi 26 août 2011 21:28
À : discuss@restlet.tigris.org
Objet : Re: Version 2: How to get XML representation

On Fri, Aug 26, 2011 at 1:05 AM, Jerome Louvel jerome.lou...@noelios.com 
wrote:
 Hi Ivano,

 Another option would be to do:

Document doc = resource.get(Document.class);

 That should just works with automagic conversion :)


That is some magic!  I just took a look at this page on the ConverterService:

   
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/331-restlet/360-restlet.html

I'm left wanting a bit more of an example other than digging into the source.  
Neat idea thought and I may have to try this out for my own classes.

--Alex Milowski

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

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


Re: Version 2: How to get XML representation

2011-08-25 Thread Alex Milowski
On Thu, Aug 25, 2011 at 10:10 AM, Ivano Carrara icarr...@studio5.it wrote:
 Hi all,

 Using Version 1 of Restlet, I built a client to get Xml from a remote server 
 and to examine it using Xpath expressions - below a fragment of code:

 Request req = new Request(Method.GET, url);
 Client client = new Client(Protocol.HTTP);
 Response resp = client.handle(req);

 DomRepresentation doc = resp.getEntityAsDom();

 How I can obtain the same doc object using the Version 2 ?

 Below the actual code:

 ClientResource resource = new ClientResource(url);
 resource.get();

 Then using resource.get().getText()); I obtain the text of my XML, but I 
 need the DOM representation to use with XPath expressions.

 With Version 2, what is the equivalent code to DomRepresentation doc = 
 resp.getEntityAsDom(); of Version 1 ?

You can either use the DocumentBuilder API from JAXP:

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  docBuilder = factory.newDocumentBuilder();
  Document doc = docBuilder.parse(new
InputSource(resource.get().getReader()));

or you can use the DomRepresentation from the XML extension:

 DomRepresentation domRep = new DomRepresentation(resource.get());
 Document doc = domRep.getDocument();

I personally use the DocumentBuilder API so I have control over the
DOM construction.

--Alex Milowski

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