Best XML Parser & advice

S

Stuart Clarke

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
 
J

Jonathan Hudson

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
 
S

Stuart Clarke

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
 
B

brabuhr

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

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

/tmp> cat x.rb
s =3D "<UserData><Time>1270242409</Time><ClientVersion>3</ClientVersion><Co=
unt>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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top