0

I have a sample XML document like

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <SearchSecretsResponse xmlns="urn:thesecretserver.com">
      <SearchSecretsResult>
        <Errors/>
        <SecretSummaries>
          <SecretSummary>
            <SecretId>86</SecretId>
            <SecretName>hostName\root</SecretName>
            <SecretTypeName>Unix Root Account (SSH)</SecretTypeName>
          </SecretSummary>
        </SecretSummaries>
      </SearchSecretsResult>
    </SearchSecretsResponse>
  </soap:Body>
</soap:Envelope>

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 ?

2 Answers 2

2

You'll need to alias the namespace.

Nokogiri::XML(xml).xpath('//foo:SecretSummary', 'foo' =>  'urn:thesecretserver.com')
Sign up to request clarification or add additional context in comments.

Comments

1

You could also remove the namespaces

doc.remove_namespaces!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.