user1191140 user1191140 - 1 year ago 57
Ruby Question

Ruby XML Parsing

I have a sample XML document like

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
<SearchSecretsResponse xmlns="">
<SecretTypeName>Unix Root Account (SSH)</SecretTypeName>

I am trying to parse it using Nokogiri. My code is

doc = Nokogiri::XML.parse(xml)
puts doc.xpath('//SecretSummary')

But this doesn't print anything. What am I doing wrong ?

Answer Source

You'll need to alias the namespace.

Nokogiri::XML(xml).xpath('//foo:SecretSummary', 'foo' =>  '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download