Consulta no XML

1. Consulta no XML

Pedro Brandão Flores da Silva
Pedro_Brandao

(usa Ubuntu)

Enviado em 05/07/2016 - 13:42h

Preciso fazer uma consulta em um XML e que o resultado dela seja o nome <name> e o <monitor>
<gateways>
<gateway_item>
<interface>wan</interface>
<gateway>192.158.29.1</gateway>
<name>WANGW</name>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<interval/>
<avg_delay_samples/>
<avg_loss_samples/>
<avg_loss_delay_samples/>
<descr><![CDATA[GVT]]></descr>
<monitor>4.2.2.2</monitor>
</gateway_item>
<gateway_item>
<interface>opt1</interface>
<gateway>207.97.91.65</gateway>
<name>EmbratelGW</name>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<interval/>
<avg_delay_samples/>
<avg_loss_samples/>
<avg_loss_delay_samples/>
<descr/>
<monitor>201.163.2.8</monitor>
<defaultgw/>
</gateway_item>
</gateways>



  


2. Re: Consulta no XML

thinomar
thinomar

(usa Linux Mint)

Enviado em 05/07/2016 - 14:55h

grep -E "name|monitor" /caminho/do/arquivo.xml | sed -e 's/<\/.*>\|<//g' | sed 's/>/: /g' 

Entrada:
<gateways>
<gateway_item>
<interface>wan</interface>
<gateway>192.158.29.1</gateway>
<name>WANGW</name>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<interval/>
<avg_delay_samples/>
<avg_loss_samples/>
<avg_loss_delay_samples/>
<descr><![CDATA[GVT]]></descr>
<monitor>4.2.2.2</monitor>
</gateway_item>
<gateway_item>
<interface>opt1</interface>
<gateway>207.97.91.65</gateway>
<name>EmbratelGW</name>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<interval/>
<avg_delay_samples/>
<avg_loss_samples/>
<avg_loss_delay_samples/>
<descr/>
<monitor>201.163.2.8</monitor>
<defaultgw/>
</gateway_item>
</gateways>

Saída:
name: WANGW
monitor: 4.2.2.2
name: EmbratelGW
monitor: 201.163.2.8

--
-I've been talking to the main computer
-And...?
-It hates me


3. Re: Consulta no XML

Pedro Brandão Flores da Silva
Pedro_Brandao

(usa Ubuntu)

Enviado em 05/07/2016 - 15:03h

Obrigado!

RESOLVIDO!!






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts