New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

demolisher

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

demolisher

  • 0.6.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Demolisher

Works in a similar fashion to Builder but is instead used for extracting information from XML files rather than building them.

== Installation

You can install using any of the following methods

$ gem install demolisher $ gem install demolisher -s http://gemcutter.org

the first two should always be stable, the latter github one should be stable but there are no guarantees.

== Example

Given the simple XML example file below

Enoch Root 01234 567 8900 enoch@example.com YES Randy Waterhouse 01234 567 8901 randy@example.com NO

we can parse it with

xml = Demolisher.demolish('addressbook.xml') xml.addressbook do puts "Version #{xml['version']}" xml.person do puts "#{xml.firstname} #{xml.lastname}: #{xml.contact.email}" puts "this person is active" if xml.active? end end

and we should get the result of

Enoch Root: enoch@example.com this person is active Randy Waterhouse: randy@example.com

== Namespaces

There is now rudimentary support for XML namespaced documents. The caveat is that if you are using a document with any XML namespaced elements you must access all elements via a namespace prefix.

As an example we have this document

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> soap:Body <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"> 14-Demolisher </ns1:IdAndName> </soap:Body> </soap:Envelope>

some of the elements define their default namespace, +getManufacturerNamesResponse+ and +IDAndNameList+ so are not prefixed. When accessing these elements they will need to be prefixed.

Additionally the list of namespaces need to known ahead of parse time. For the above document the list of namespaces is

  1. http://schemas.xmlsoap.org/soap/envelope/ as soap
  2. http://services.somewhere.com
  3. http://domain.somewhere.com as ns1

as namespace two has no prefix, its a default namespace, we will assign it one when creating the hash of namespaces.

namespaces = { 'soap' => "http://schemas.xmlsoap.org/soap/envelope/", 'ns0' => "http://services.somewhere.com", 'ns1' => "http://domain.somewhere.com" }

this hash of namespaces is then passed to Demolisher

xml = Demolisher.demolish('soap.xml', namespaces) xml.soap :Envelope do xml.soap :Body do xml.ns0 :getManufacturerNamesResponse do xml.ns0 :IDAndNameList do puts xml.ns1(:IdAndName).strip end end end end

the result of this will be

14-Demolisher

== Copyright

Copyright (c) 2009 Geoff Garside. See LICENSE for details.

FAQs

Package last updated on 23 Mar 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc