parsing

Rails 2.3.8: how to parse JSON with field names other than DB columns

I'm sure there's an easy solution for this but I'm new to Rails and need help with syntax. In my controller I have: @products = Product.all format.json { render :json => @products } And it works fine, returning data with the default column names used in the DB: "product": { "created_at": "2010-10-08T17:24:27Z", "id": 24, "prod...

Easily extendable Objective C XML parser?

If I knew how to phrase this I could probably find the answer on Google. I need an XML parser which I can call out to other XML parsers with. For example: <car> <driver> <name /> <age /> <height /> </driver> <make> <name /> <nationality /> <age /> </make> <engine> ...

Split DateTime strings when converting

Hi I'm writing a C# class that will convert strings to dates. Pretty easy I guess. The class accepts formatstrings like "yyyy-MM-dd" and inputstrings like "2010-10-10" However I have some cases that give me trouble: format "yyyyMMdd" input "19950000" or format "dd-MM-yyyy" input "00-06-2001" Note that these cases have zeroes ('0...

whats the easiest way to convert "6.00000000000000" to an integer property

i have an Person object with an age property (int) i am parsing a file and this value is coming in this format "6.00000000000000" what is the best way to convert this string into an int in C# Convert.ToInt32() or Int.Parse() gives me an exception: Input string was not in a correct format. ...

Parsing excel cell. How?

We have Excel file. This file is in a cells with the name "address" containing the line, for example: The Accounts Department, National Bank Ltd, 20 Lombard Str., London 3 WRS, England Need to share information in the cell groups. That is, we must have the following cells: "country": England "city": London "street": Lombard Str. .......

Parsing HTML and replacing strings

I have a large quantity of partial HTML stored in a CMS database. I'm looking for a way to go through the HTML and find any <a></a> tags that don't have a title and add a title to them based on the contents of the tags. So if I had <a href="somepage">some text</a> I'd like to modify the tag to look like: <a title="some text" href="som...

Solid resources for an amateur to learn about writing parsing and state machines?

Books, articles, anything. The language doesn't matter too much as I can probably figure it out. I just want something that is fairly deep, very practical and, most importantly, easy to understand. Thanks guys :) ...

Template class using Gold Parser and the Klimstra engine...

I'm using Klimstra's VB.NET template from the "Create skeleton program" of the GOLD parser but the resulting template has methods with the overrides keyword and inherits from "TemplateParser".. that kind of threw me off, am I supposed to create the TemplateParser class or is there a tool to create it? I thought that the "create skeleton"...

SQL engine for only SELECT statment - hand written parser in c++

Hi, I am a newbie of compilers, but i got a project SQL engine - for only select statement. For this i have to use only hand written parser and engine. I studied the samples of LL(k) grammar and recursive descent techniques(suggested by stackoverflow for writing parser by hand). But in any of the samples, didn't find the way to construc...

parse XML and convert to a Collection

<inputs> <MAT_NO>123</MAT_NO> <MAT_NO>323</MAT_NO> <MAT_NO>4223</MAT_NO> <FOO_BAR>122</FOO_BAR> <FOO_BAR>125</FOO_BAR> </inputs> I've to parse the above the XML. After parsing, i want the values to be in a Map<String, List<String>> with Key values corresponding to the child nodes - MAT_NO, FOO_BAR and values - the values of t...

Apple pList form of XML can I parse it through Android Java?

Can we parse the iPhone/iPad based pList XML from Java on Android? Please tell me if any such library you have used or know about? ...

How to parse a double formatted according to a locale settings in C++

I've found a problem with the strtod method which I've used all this time. First of all it doesn't understand non-point decimal separator, so I've forced to use this: std::replace(sSource.begin(), sSource.end(), getDecimalSeparator(), '.'); But no I've found another problem and didn't found how to resolve it yet. If the value is negat...

Evaluation of a small math type language that supports one variable

I have written the parser that reads the string input. That works. I have also written the evaluator that spits out the result. But there is one small detail that I'm having trouble implementing. Look at the following example: +(sw+(2,2),sr) The sw construct of this tiny language is suppose to evaluate "+(2,2)" and store it somewhere...

Retrieve XML from web using C#

Problem: The XML file I want to retrieve has a reference to a XSLT and thus the response contains only the transformed XHTML content. For example: URL:http://armory.wow-europe.com/arena-ladder.xml?ts=2&amp;b=Blackout If you open up this URL with Firefox you can actually see the original XML that is retrieved from the webserver. And you ...

Optimizing Bison Grammar

I have this grammar of a C# like language, and I want to make a parser for it, but when I put the grammar it tells me about Shift/Reduce conflicts. I tried to fix some but I can't seem to find another way to improve this grammar. Any help would be greatly appreciated :D Here's the grammar: Program: Decl | Program Decl ; D...

Parsing HTTP Get requests into constituent fields

I have fields like: "GET /?blahblahblah HTTP/1.1" 200 43 "http://www.thesun.co.uk/sol/homepage/" 1 blahblah - "en-gb" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB0.0; FunWebProducts; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" i'm looking for a java library o...

ANTLR (or alternative): decoupling parsing from evaluation

I have a relatively simple DSL that I would like to handle more robustly than a bunch of manually-coded java.util.regex.Pattern statements + parsing logic. The most-quoted tool seems to be ANTLR. I'm not familiar with it and am willing to give it a try. However I get a little leery when I look at the examples (e.g. the ANTLR expression ...

Convert HTML to plain text in Java

I need to convert HTML to plain text. My only requirement of formatting is to retain new lines in the plain text. New lines should be displayed not only in the case of < br > but other tags, eg. < tr/>, < /p> leads to a new line too. Sample HTML pages for testing are: "http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chap...

Enumerate regex match names/values

What is the C# equivalent of this pseudo-code? var pattern = ...; var lookup = new Dictionary<string, string>(); foreach (var group in new Regex(pattern).Matches()) { lookup[group.Name] = group.Value; } I don't see any System.Text.RegularExpressions group-related object that exposes the group name. What am I missing? What I'm a...

Convert string to model

Let's say I have this object: public struct Line { public string Name { get; set; } public int Value { get; set; } public string Alias { get; set; } } And I have a file with lines following this syntax: garbagedata|moregarbagedata|Name|garbagedata3|Value|garbagedatamaximums|Alias\n Note that moregarbagedata[x] may or ma...