user1191140 user1191140 - 8 months ago 13
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 ?


You'll need to alias the namespace.

Nokogiri::XML(xml).xpath('//foo:SecretSummary', 'foo' =>  '')