# Trouble with rexml

**URL:** <https://www.ruby-forum.com/t/trouble-with-rexml/71770>\
**Category:** Ruby\
**Created:** [February 22, 2006, 9:02am UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770 "2006-02-22T09:02:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 22, 2006, 9:02am UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770/1 "2006-02-22T09:02:04Z")

</div>

I read XML file using REXML.  
The XML file contains Korean charactors.

If I print the file using REXML::Document.write $stdout, everything is  
okay.( means Korean is printed out narmaly )  
But, if I try again using REXML::Element.text, Korean charactors are  
broken.( some strange charactors )

ARe there any solution for this?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 22, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770/2 "2006-02-22T15:09:14Z")

</div>

On 2/22/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I read XML file using REXML.  
> The XML file contains Korean charactors.
> 
> If I print the file using REXML::Document.write $stdout, everything is  
> okay.( means Korean is printed out narmaly )  
> But, if I try again using REXML::Element.text, Korean charactors are  
> broken.( some strange charactors )
> 
> ARe there any solution for this?

What encoding scheme did you use?  
Show me the content of Element.text.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 23, 2006, 12:55am UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770/3 "2006-02-23T00:55:49Z")

</div>

Gyoung-Yoon N. wrote:

> >

Dear Yoon,

Noh might have already helped you out and my suggestion here may not be  
relevant, but I wonder what method, e.g. puts, print or p, you used to  
print the return of element.text. The element.text method only returns  
text data but doesn’t print. (You can see something on the console if  
you are using something interactive, but it may not appear as the string  
you expected.)

Have you tried like these lines?  
$stdout.puts element.text  
and  
$stdout.puts element.to\_s  
The $stdout.puts method shows the character string obtained from the  
object (the return value of element.text or element.to\_s in the cases  
above).  
Some others like  
p element.text  
may not show the string you expected, but it does show a representation  
of the object which is not necessarily a character string.

cheers,  
nori

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 23, 2006, 7:28am UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770/4 "2006-02-23T07:28:22Z")

</div>

On 2/23/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think it may be a problem of REXML.  
> If I print [element].to\_s, the string is already broken.
> 
> Are there another XML library for RUBY?

What did they look like? Show the result of “p element”, for example:

irb(main):011:0\> puts Iconv.iconv(‘utf-8’, ‘euc-kr’,  
“\267\347\272\361”).first  
ç?·â?¤í?¬  
=\> nil  
irb(main):012:0\> p Iconv.iconv(‘utf-8’, ‘euc-kr’,  
“\267\347\272\361”).first  
“\353\243\250\353\271\204”  
=\> nil

Anyone who willing to reply your question, need to see the  
internal representation of the broken strings like latter form.  
Actually, that’s not broken. Don’t lose hope. 🙂

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 23, 2006, 2:29am UTC](https://www.ruby-forum.com/t/trouble-with-rexml/71770/5 "2006-02-23T02:29:15Z")

</div>

I think it may be a problem of REXML.  
If I print [element].to\_s, the string is already broken.

Are there another XML library for RUBY?
