View previous topic :: View next topic |
Author |
Message |
Kernel78 Moderator
Joined: 24 Jun 2005 Posts: 3654
|
Posted: Sun Oct 11, 2009 2:44 pm Post subject: Parsing XML in bash |
|
|
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 |
|
|
!equilibrium Bodhisattva
Joined: 06 Jun 2004 Posts: 2109 Location: MI/BG/LC
|
Posted: Mon Oct 12, 2009 6:52 am Post subject: |
|
|
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 |
|
|
Apetrini Veteran
Joined: 09 Feb 2005 Posts: 1158
|
Posted: Mon Oct 12, 2009 7:26 am Post subject: |
|
|
@!equilibrium: che fico! Questa mi mancava... _________________ Linux ape 2.6.31-vanilla. Paludis since 0.28.0. |
|
Back to top |
|
|
Kernel78 Moderator
Joined: 24 Jun 2005 Posts: 3654
|
Posted: Mon Oct 12, 2009 8:30 am Post subject: |
|
|
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 |
|
|
oRDeX Veteran
Joined: 19 Oct 2003 Posts: 1325 Location: Italy
|
Posted: Mon Oct 12, 2009 1:00 pm Post subject: |
|
|
Apetrini wrote: | @!equilibrium: che fico! Questa mi mancava... |
Concordo!!
Xpath in perl da riga di comando |
|
Back to top |
|
|
|