From: Stuart Clarke on
Hey all,

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

<UserData><Time>1270242409</Time><ClientVersion>3</ClientVersion><Count>0</Count></UserData>

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
--
Posted via http://www.ruby-forum.com/.

From: Jonathan Hudson on
On Wed, 11 Aug 2010 04:59:09 +0900, Stuart Clarke 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




From: Stuart Clarke on
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 Hudson wrote:
> On Wed, 11 Aug 2010 04:59:09 +0900, Stuart Clarke 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

--
Posted via http://www.ruby-forum.com/.

From: brabuhr on
On Tue, Aug 10, 2010 at 4:34 PM, Stuart Clarke
<stuart.clarke1986(a)gmail.com> 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 = "<UserData><Time>1270242409</Time><ClientVersion>3</ClientVersion><Count>0</Count></UserData>"

require 'rexml/document'

REXML::Document.new(s).root.each_element("/UserData/Time"){|e|
puts "Time: " + e.text
}

/tmp> ruby x.rb
Time: 1270242409

From: Stuart Clarke on
Thanks for this.

unknown wrote:
> On Tue, Aug 10, 2010 at 4:34 PM, Stuart Clarke
> <stuart.clarke1986(a)gmail.com> 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:
--
Posted via http://www.ruby-forum.com/.