Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Parsing XML in bash
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano
View previous topic :: View next topic  
Author Message
Kernel78
Moderator
Moderator


Joined: 24 Jun 2005
Posts: 3654

PostPosted: Sun Oct 11, 2009 2:44 pm    Post subject: Parsing XML in bash Reply with quote

Ciao a tutti, stavo cercando qualche metodo per poter lavorare da bash sui feed restituiti dalla chiamate alle API di Google.
Devo estrarre il contenuto di alcuni tag e il valore di alcuni attributi e grep mi sembra decisamente inadeguato.

Potrei provare a sbattermi con sed ma mi sembra un casino e decisamente poco adattabile, ovviamente il parser sarebbe lo strumento ideale ma non ne trovo uno da usare in bash ...
_________________
Le tre grandi virtù di un programmatore: pigrizia, impazienza e arroganza. (Larry Wall).
Prima di postare un file togli i commenti con
Code:
grep -vE '(^[[:space:]]*($|(#|!|;|//)))'
Back to top
View user's profile Send private message
!equilibrium
Bodhisattva
Bodhisattva


Joined: 06 Jun 2004
Posts: 2109
Location: MI/BG/LC

PostPosted: Mon Oct 12, 2009 6:52 am    Post subject: Reply with quote

puoi installare dev-perl/XML-XPath e usare il binario xpath dallo script in questo modo:

Code:
RESULTS=$( xpath "/mio/path/file.xml" "//key[xxxx]/following-sibling::map[1]/string/text()" )

_________________
Arch Tester for Gentoo/FreeBSD
Equilibrium's Universe

all my contents are released under the Creative Commons Licence by-nc-nd 2.5
Back to top
View user's profile Send private message
Apetrini
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1158

PostPosted: Mon Oct 12, 2009 7:26 am    Post subject: Reply with quote

@!equilibrium: che fico! Questa mi mancava...
_________________
Linux ape 2.6.31-vanilla. Paludis since 0.28.0.
Back to top
View user's profile Send private message
Kernel78
Moderator
Moderator


Joined: 24 Jun 2005
Posts: 3654

PostPosted: Mon Oct 12, 2009 8:30 am    Post subject: Reply with quote

ho trovato anche
Code:
app-text/xmlstarlet
ma adesso sto impazzendo con questi tremendi namespace ...
_________________
Le tre grandi virtù di un programmatore: pigrizia, impazienza e arroganza. (Larry Wall).
Prima di postare un file togli i commenti con
Code:
grep -vE '(^[[:space:]]*($|(#|!|;|//)))'
Back to top
View user's profile Send private message
oRDeX
Veteran
Veteran


Joined: 19 Oct 2003
Posts: 1325
Location: Italy

PostPosted: Mon Oct 12, 2009 1:00 pm    Post subject: Reply with quote

Apetrini wrote:
@!equilibrium: che fico! Questa mi mancava...

Concordo!!

Xpath in perl da riga di comando 8O 8O 8O
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum