### Home Classes Methods

### In Files

- lib/xmpp4r/rexmladdons.rb

### Parent

Object

### Methods

- ::import
- #==
- #delete_elements
- #each_elements
- #first_element
- #first_element_content
- #first_element_text
- #import
- #replace_element_content
- #replace_element_text
- #typed_add

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# REXML::Element

this class adds a few helper methods to REXML::Element

### Public Class Methods

import(xmlelement) click to toggle source

    # File lib/xmpp4r/rexmladdons.rb, line 127
    def self.import(xmlelement)
      self.new(xmlelement.name).import(xmlelement)
    end

### Public Instance Methods

==(o) click to toggle source

Test for equality of two elements, useful for assert_equal in test cases. Tries to parse String o as XML.

See Test::Unit::Assertions

    # File lib/xmpp4r/rexmladdons.rb, line 143
    def ==(o)
      return false unless self.kind_of? REXML::Element
      if o.kind_of? REXML::Element
        # Ok
      elsif o.kind_of? String
        # Parse o
        begin
          o = REXML::Document.new(o).root
        rescue REXML::ParseException
          return false
        end
      else
        # Cannot compare with anything other than Elements or Strings
        return false
      end

      return false unless name == o.name

      attributes.each_attribute do |attr|
        return false unless attr.value == o.attributes[attr.name]
      end

      o.attributes.each_attribute do |attr|
        return false unless attributes[attr.name] == attr.value
      end

      children.each_with_index do |child,i|
        return false unless child == o.children[i]
      end

      return true
    end

delete_elements(element) click to toggle source

Deletes one or more children elements, not just one like REXML::Element#delete_element

    # File lib/xmpp4r/rexmladdons.rb, line 134
    def delete_elements(element)
      while(delete_element(element)) do end
    end

each_elements(*els, &block) click to toggle source

    # File lib/xmpp4r/rexmladdons.rb, line 20
    def each_elements(*els, &block)
      els.inject([ ]) do |res, e|
        res + each_element(e, &block)
      end
    end

first_element(e, namespace = nil) click to toggle source

Returns first element of name `e`

    # File lib/xmpp4r/rexmladdons.rb, line 63
    def first_element(e, namespace = nil)
      if namespace
        each_element_with_attribute("xmlns", namespace, 1, e) { |el| return el }
      else
        each_element(e) { |el| return el }
      end
      return nil
    end

first_element_content(e, namespace = nil) click to toggle source

This method works like `first_element_text` except that it returns content of all children, not just the value of the first child text element.

Returns content of first element of name `e`

    # File lib/xmpp4r/rexmladdons.rb, line 89
    def first_element_content(e, namespace = nil)
      el = first_element(e, namespace)
      if el
        return el.children.join
      else
        return nil
      end
    end

first_element_text(e, namespace = nil) click to toggle source

Returns text of first element of name `e`

    # File lib/xmpp4r/rexmladdons.rb, line 74
    def first_element_text(e, namespace = nil)
      el = first_element(e, namespace)
      if el
        return el.text
      else
        return nil
      end
    end

import(xmlelement) click to toggle source

import this element's children and attributes

    # File lib/xmpp4r/rexmladdons.rb, line 109
    def import(xmlelement)
      if @name and @name != xmlelement.name
        raise "Trying to import an #{xmlelement.name} to a #{@name} !"
      end
      add_attributes(xmlelement.attributes.clone)
      @context = xmlelement.context
      xmlelement.each do |e|
        if e.kind_of? REXML::Element
          typed_add(e.deep_clone)
        elsif e.kind_of? REXML::Text
          add_text(e.value)
        else
          add(e.clone)
        end
      end
      self
    end

replace_element_content(e, c, namespace = nil) click to toggle source

Replaces or adds a child element of name `e` with content of `t`.

    # File lib/xmpp4r/rexmladdons.rb, line 43
    def replace_element_content(e, c, namespace = nil)
      el = first_element(e, namespace)
      if el.nil?
        el = REXML::Element.new(e)
        el.add_namespace(namespace)
        add_element(el)
      end
      if c
        el.children.each do |ch|
          ch.remove
        end
        c.root.children.each do |ch|
          el.add ch
        end
      end
      self
    end

replace_element_text(e, t, namespace = nil) click to toggle source

Replaces or adds a child element of name `e` with text `t`.

    # File lib/xmpp4r/rexmladdons.rb, line 28
    def replace_element_text(e, t, namespace = nil)
      el = first_element(e, namespace)
      if el.nil?
        el = REXML::Element.new(e)
        el.add_namespace(namespace)
        add_element(el)
      end
      if t
        el.text = t
      end
      self
    end

typed_add(e) click to toggle source

This method does exactly the same thing as add(), but it can be overriden by subclasses to provide on-the-fly object creations. For example, if you import a REXML::Element of name 'plop', and you have a Plop class that subclasses REXML::Element, with typed_add you can get your REXML::Element to be "magically" converted to Plop.

    # File lib/xmpp4r/rexmladdons.rb, line 103
    def typed_add(e)
      add(e)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.