XML: parsing of the Google contacts XML file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML: parsing of the Google contacts XML file
# 1  
Old 12-23-2012
XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere.

I can not supply any sample file as it contains private data but you can download your own contacts using this script:
Code:
#!/bin/sh

# imports Google Contacts
# imported data is stored in contacts.xml file (current directory)

# You will need curl and xmllint tools

LOGIN="your.login@gmail.com"
PASSW="your_passw"

AUTH=$(curl --silent https://www.google.com/accounts/ClientLogin \
-d Email=$LOGIN \
-d Passwd=$PASSW \
-d accountType=GOOGLE \
-d service=cp \
-d Gdata-version=3.0 | grep '^Auth')

curl --silent -o /tmp/contacts.tmp https://www.google.com/m8/feeds/contacts/default/full?max-results=5 \
--header "Authorization: GoogleLogin auth=${AUTH#*=}" \
--header "GData-Version: 3.0" \

# format nicely the Google output
xmllint --format /tmp/contacts.tmp > contacts.xml

I can get the root node:
Code:
$ xmllint --xpath '/' contacts.xml

But it fails when I try the first node below root: <feed>
Code:
$ xmllint --xpath '/feed' contacts.xml 
XPath set is empty

# 2  
Old 12-23-2012
Please understand that you need to supply a sample file if you expect people to help you. Simply obscure your private data or make up some replacement data.
# 3  
Old 12-23-2012
Here you go. A bit tedious to obscure a Google contacts file. This one contains 3 records.

Last edited by ripat; 12-23-2012 at 03:50 PM..
# 4  
Old 12-23-2012
I found this link reporting a similar problem and solution suggesting 2 different approaches. So I thought to share it with you, not sure if it will help.
# 5  
Old 12-24-2012
Quote:
Originally Posted by bipinajith
I found this link reporting a similar problem and solution suggesting 2 different approaches. So I thought to share it with you, not sure if it will help.
Thanks for the hint but I have seen that post but it's about another problem.

There is something wrong with that Google XML file -or with my way to access it. When I grep a record in the xmllint shell, it returns some wild card instead of the node path:
Code:
$ xmllint --shell cts.xml 
/ > grep Arthur
/*/*[16]/*[5] : tan        9 Arthur M.
/*/*[16]/gd:name/gd:fullName : tan        9 Arthur M.
/*/*[16]/gd:name/gd:givenName : ta-        6 Arthur
/ >

My understanding is that it should have returned a full path to the node. Something like:
Code:
/feed/entry/gd:name/gd:fullName

Could that be that the file is corrupt? A xmllint --debug doesn't return anything abnormal though.

But I could be on something:

Code:
xmllint --valid cts.xml
cts.xml:2: validity error : Validation failed: no DTD found !
tp://schemas.google.com/g/2005" gd:etag="W/&quot;A0AFRHc4eit7I2A9WhNVEkU.&quot;"
                                                                               ^

But all other test files that work all right with xmllint generate the same error on validation...

Again, I am getting nowhere...
# 6  
Old 12-24-2012
Quote:
Could that be that the file is corrupt? A xmllint --debug doesn't return anything abnormal though.
No, your sample file is not corrupt. It is valid XML. It just has no DTD - which is fine.

It has multiple namespaces in it, that is why xmllint does not work.

Last edited by fpmurphy; 12-24-2012 at 10:47 AM..
# 7  
Old 12-24-2012
Quote:
Originally Posted by fpmurphy
It has multiple namespaces in it, that is why xmllint does not work.
Could xsltproc be able to extract data despite that multiple namespace thing?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with parsing xml file

Hi, Need help with parsing xml data in unix and place it in a csv file. My xml file looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <iwgroups> <nextid value="128"> </nextid> <iwgroup name="RXapproval" id="124" display-name="RXapproval"... (11 Replies)
Discussion started by: ajayakunuri
11 Replies

2. UNIX for Dummies Questions & Answers

Parsing XML file

I want to parse xml file sample file....... <name locale="en">my_name<>/name><lastChanged>somedate</lastChanged><some more code here> <name locale="en">tablename1<>/name><lastChanged>somedate</lastChanged> <definition><dbquery><sources><sql type="cognos">select * from... (10 Replies)
Discussion started by: ms2001
10 Replies

3. Shell Programming and Scripting

Parsing an XML file

Hello, I have the following xml file as an input. <?xml version="1.0" encoding="UTF-8"?> <RECORDS PS3_VERSION="1104_01"><RECORD> <POI_ID>931</POI_ID> <SUPPLIER_ID>2</SUPPLIER_ID> <POI_PVID>997920846</POI_PVID> <DB_ID>1366650925</DB_ID> <REGION>H1</REGION> <POI_NAME NAME_TYPE="Official"... (4 Replies)
Discussion started by: ramky79
4 Replies

4. Shell Programming and Scripting

parsing xml file

Hello! We need to parse weblogic config.xml file and display rows in format: machine:listen-port:name:application_name In our enviroment the output should be (one line for every instance): Crm-Test-Web:8001:PIA:peoplesoft Crm-Test-Web:8011:PIA:peoplesoft... (9 Replies)
Discussion started by: annar
9 Replies

5. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

Parsing xml file

hi guys, great help to the original question, can i expand please? i have large files filled with blocks like this <Placemark> network type: hot line1 line2 line3 <styleUrl>red.png</styleUrl> </Placemark> <Placemark> network type: cold line1 line2 line3... (3 Replies)
Discussion started by: garvald
3 Replies

7. UNIX for Dummies Questions & Answers

Help parsing a XML file ....

Well I have read several threads on the subject ... but being a newbie like me makes it hard to understand ... What I need is the following: Input data: ------- snip --------- <FavouriteLocations> <FavouriteLocations class="FavouriteList"><Item... (6 Replies)
Discussion started by: misak
6 Replies

8. Shell Programming and Scripting

XML file parsing using script

Hi I need some help with XML file parsing. I have an XML file with the below tag, I need a script to identify the value of srvcName which is this case is "AAA srvc name". I need to put contents of this value which is AAA srvc and name into different variables using an array and then reformat it... (6 Replies)
Discussion started by: zmfcat1
6 Replies

9. UNIX for Advanced & Expert Users

Parsing xml file using Sed

Hi All, I have this(.xml) file as: <!-- define your instance here --> <instance name='ins_C2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' > <property> </property> </instance> I want output as: <!-- define your instance here --> <instance... (3 Replies)
Discussion started by: kapilkinha
3 Replies
Login or Register to Ask a Question