# Best XML Parser & advice

**URL:** <https://www.ruby-forum.com/t/best-xml-parser-advice/193081>\
**Category:** Ruby\
**Created:** [August 10, 2010, 9:59pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081 "2010-08-10T21:59:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 10, 2010, 9:59pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081/1 "2010-08-10T21:59:07Z")

</div>

Hey all,

I have identified a file, which is not an XML file however its content  
represents XML e.g.

127024240930

I have clearly identified in this file where the the tags are however I  
have a few issues to overcome.

First, each character is delimited by a null character - this is not a  
problem I am I have found a solution to remove the null characters thus  
giving text similar to that above. I am not struggling how I get from an  
array containing the above data with null characters removed to parsing  
the XML?

What does everyone suggest as to the best XML library and the best way  
to parse the data as it stands in an array instead of an XML file.

Many thanks

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 10, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081/2 "2010-08-10T22:14:29Z")

</div>

On Wed, 11 Aug 2010 04:59:09 +0900, Stuart C. wrote:

> First, each character is delimited by a null character - this is not a  
> problem I am I have found a solution to remove the null characters thus  
> giving text similar to that above. I am not struggling how I get from an  
> array containing the above data with null characters removed to parsing  
> the XML?

Isn’t that form of delimiting more commonly called UTF-16 (which  
happens also to be a valid XML encoding …)?

-jh

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 10, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081/3 "2010-08-10T22:34:26Z")

</div>

Ok, not to familIar with encoding, so thanks for that.

Would you suggest rexml, e.g.

xmlData.elements.each(“userdata/time”){  
|e| puts "Time : " + e.attributes[“time”]  
}

Thanks  
Jonathan H. wrote:

> On Wed, 11 Aug 2010 04:59:09 +0900, Stuart C. wrote:
> 
> > First, each character is delimited by a null character - this is not a  
> > problem I am I have found a solution to remove the null characters thus  
> > giving text similar to that above. I am not struggling how I get from an  
> > array containing the above data with null characters removed to parsing  
> > the XML?
> 
> Isn’t that form of delimiting more commonly called UTF-16 (which  
> happens also to be a valid XML encoding …)?
> 
> -jh

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 10, 2010, 10:51pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081/4 "2010-08-10T22:51:56Z")

</div>

On Tue, Aug 10, 2010 at 4:34 PM, Stuart C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> xmlData.elements.each(“userdata/time”){  
> |e| puts "Time : " + e.attributes[“time”]  
> }

Here’s a quick example using REXML on the sample string you provided:

/tmp\> cat x.rb  
s =  
“127024240930”

require ‘rexml/document’

REXML::Document.new(s).root.each\_element(“/UserData/Time”){|e|  
puts "Time: " + e.text  
}

/tmp\> ruby x.rb  
Time: 1270242409

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 11, 2010, 1:30pm UTC](https://www.ruby-forum.com/t/best-xml-parser-advice/193081/5 "2010-08-11T13:30:58Z")

</div>

Thanks for this.

unknown wrote:

> On Tue, Aug 10, 2010 at 4:34 PM, Stuart C.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > xmlData.elements.each(“userdata/time”){  
> > ï¿½ |e| puts "Time : " + e.attributes[“time”]  
> > }
> 
> Here’s a quick example using REXML on the sample string you provided:
