From: Stuart Clarke on 10 Aug 2010 15:59 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 10 Aug 2010 16:12 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 10 Aug 2010 16:34 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 10 Aug 2010 16:51 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 11 Aug 2010 07:32 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/.
|
Pages: 1 Prev: TkVariable and accents Next: rb_set_kcode equivalent for 1.9.x |