# REXML namespace support

**URL:** <https://rubytalk.org/t/rexml-namespace-support/2018>\
**Category:** ruby-talk\
**Created:** [27 September 2002 13:45 UTC](https://rubytalk.org/t/rexml-namespace-support/2018 "2002-09-27T13:45:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volkmann\_Mark](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Volkmann\_Mark](https://rubytalk.org/u/Volkmann_Mark)\
**Post date:** [27 September 2002 13:45 UTC](https://rubytalk.org/t/rexml-namespace-support/2018/1 "2002-09-27T13:45:45Z")

</div>

Is there an easy way in REXML to get the namespace that is associated with a  
given prefix?

> **···**
>
> * * *
> 
> WARNING: All e-mail sent to and from this address will be received or  
> otherwise recorded by the A.G. Edwards corporate e-mail system and is  
> subject to archival, monitoring or review by, and/or disclosure to,  
> someone other than the recipient.
> 
> * * *

---

<div class="post-metadata">

**Author:** ![Kouhei\_Sutou](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@Kouhei\_Sutou](https://rubytalk.org/u/Kouhei_Sutou)\
**Post date:** [27 September 2002 14:33 UTC](https://rubytalk.org/t/rexml-namespace-support/2018/2 "2002-09-27T14:33:12Z")

</div>

Message-ID: [89539780CB9BD51182270002A5897DF602C6D670@hqempn04.agedwards.com](mailto:89539780CB9BD51182270002A5897DF602C6D670@hqempn04.agedwards.com)

> Is there an easy way in REXML to get the namespace that is associated with a  
> given prefix?

You can use REXML::Element#namespace if you are using a-la DOM API.

----------Example-----------------  
require ‘rexml/document’

xml = \<\<XML

\<?xml version='1.0'?\> XML

doc = REXML::Document.new(xml)

p doc.root.namespace(“fuga”)  
p doc.elements[“/a/b”].namespace(“fuga”)  
p doc.elements[“/a/b/c”].namespace(“fuga”)  
p doc.elements[“/a/d”].namespace(“fuga”)  
----------Example-----------------

----------Output------------------  
“foo”  
“foo”  
“hoge”  
“bar”  
----------Output------------------

> **···**
>
> From: “Volkmann, Mark” [Mark.Volkmann@AGEDWARDS.com](mailto:Mark.Volkmann@AGEDWARDS.com)  
> Subject: REXML namespace support  
> Date: Fri, 27 Sep 2002 22:45:45 +0900
> 
> ======================  
> Kouhei Sutou  
> [kou@cneti.net](mailto:kou@cneti.net)
