how to parse google contact feed (xml or json) using php - gdata-api

I'm trying to parse the google contact feed using php, below is the example of the xml feed that i get from google
<entry>
<id>http://www.google.com/m8/feeds/contacts/sample%40gmail.com/base/63a9d180dd7f506</id>
<updated>2010-11-23T10:00:40.848Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/>
<title type='text'>######this is the sample title i need to get#####</title>
<link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='#####this is the link i need#####'/>
<link rel='self' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/sample40gmail.com/full/680dd7f506'/>
<link rel='edit' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/sample%40gmail.com/full/0dd7f506/12940848000'/>
<gd:email rel='http://schemas.google.com/g/2005#other' address='########here is the address that i need to get#######' primary='true'/>
</entry>
how to parse out those information that i have marked using php?

Convert the result into Json ..(For easy parsing )
Call the API with the parameter "alt=json" You will get results in Json format ..

Related

Xpath not working in camel route

I'm sending soap xml through exchange object.When i try to route the request using xpath in apache camel,i'm not able to execute it properly.Please suggest
My Exchange body xml is
<Envelope><Header>
</Header>
<Body>
<Choice>
<Selector>1</selector>
</Choice>
</Body>
</Envelope>
My Camel Route
from(direct:XX)
.to(when(xpath("body()/Choice/Selector/.",String.class)=='1')
.to("direct:X")
.otherwise()
.to("direct:Y")
your Envelope cannot look like that. it must be something like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
...
body()/Choice/Selector/. is not an Xpath. there is no such thing like body() in XPath.
Assuming that you have a SOAP Body content in the Exchange.body processed by some JAX-WS endpoint XPath will be
/Choice/Selector or /Choice/Selector/text() if it is an element with mixed content
BTW: if your Envelope is real example you try to test do not forget to fix your XML - you have wrong <Selector>1</selector> Tag names are case sensitive. It must be <Selector>1</Selector>

How to get tags inside of CDATA with Xpath3 on Anypoint Mule?

I am trying to get the tag Decision inside a PDP response with Xpath3 on Anypoint mule.
This is the response of the PDP:
<ns:getDecisionResponse xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://org.apache.axis2/xsd">
<ns:return><![CDATA[<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:syntax-error"/><StatusMessage>Invalid request : DOM of request element can not be created from String</StatusMessage></Status></Result></Response>]]></ns:return>
</ns:getDecisionResponse>
The problem is that I can't access the tags which are inside of the CDATA.
This is what I was trying to do:
#[xpath3('/ns:getDecisionResponse/ns:return/(the problem is here...)',payload, 'STRING')]
Thanks in advance!
Juan Andrés
You can use the regex expression to remove the CDATA from your XPATH3 as following :-
<logger message="#[xpath3('/*:getDecisionResponse/*:return',payload, 'STRING').replaceAll("[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\x{10000}-\\x{10FFFF}]", "")]" level="INFO" doc:name="Logger"/>
reference :- http://www.rgagnon.com/javadetails/java-sanitize-xml-string.html
Now once you get the xml here from your CDATA you need to perform another XPATH3 extraction to get you required value from the the xml

How can I pull out date & location that doesn't have its own tag and put into separate tags?

I want to create an RSS feed using Yahoo! Pipes. The feed source coming from a website in XML format doesn't have a date/time in its own tags for every item. How can I pull out this content (date & location event) and put it in 2 tags using Yahoo Pipes? The content is in <description> tag.
<description>
<![CDATA[ 2013/11/06 # Polytechnique Montréal - Pavillon Lassonde<br/><br/>
...
</description>
Can anyone show me how to do this using Yahoo! Pipes?

Deserialize/Pulling a Spring's RestTemplate response from Atom source

I'm trying to use Spring's RestTemplate to get a response from an atom source. Is there a way to easily pull values from the response or deserialize it?
The response:
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
<id>https://apps-apis.google.com/a/feeds/domain/2.0/blah/verification/mx</id>
<updated>2013-03-19T19:47:02.805Z</updated>
<apps:property name='verified' value='false'/>
</entry>
Parse the feed with Abdera or ROME. They have nice representations of Atom feeds and feed entries with all their composing types.

jqGrid local data as XML

Can I access local XML files as data in jqGrid?
You can load the contents of the XML file in a string variable and use datatype: 'xmlstring' (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#xml_string). It will work.
I could run a local example using xmlstring method after modify the example code that I saw in: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#xml_string
My modified code is:
var mystr =
"<?xml version='1.0' encoding='utf-8'?>"+
"<invoices>"+
"<rows>"+
"<row>"+
"<cell>data1</cell>"+
"<cell>data2</cell>"+
"<cell>data3</cell>"+
"<cell>data4</cell>"+
"<cell>data5</cell>"+
"<cell>data6</cell>"+
"</row>"+
"</rows>"+
"</invoices>";
Instead of:
var mystr =
"<?xml version='1.0' encoding='utf-8'?>
<invoices>
<rows>
<row>
<cell>data1</cell>
<cell>data2</cell>
<cell>data3</cell>
<cell>data4</cell>
<cell>data5</cell>
<cell>data6</cell>
</row>
</rows>
</invoices>";
You want to access an XML file stored on the client's machine via JavaScript? I don't think that can be done.
The more common scenario is pulling your XML via an Ajax call. I'd also look at the "local" option on the jqGrid wiki. You could embed your data as JSON/XML in the HTML page and read it in when setting up your jqGrid.

Resources