Questions tagged [parsing]

Parsing refers to breaking an artifact into its constituent elements and capturing the relationship between those elements. This tag isn't for questions about the self hosted Parse Platform (use the [parse-platform] tag) or parse errors in a particular programming language (use the appropriate language tag instead).

Parsing refers to the action by software of breaking an artifact into its constituent elements and capturing the relationship between those elements.

When the artifact is a stream of arbitrary text, parsing is often used to mean breaking the stream into constituent atoms (called words, tokens or lexemes).

When the artifact is a stream of natural language text, parsing is used to mean breaking the stream into natural language elements (words and punctuation) and discovering the structure of the text as phrases or sentences.

When the artifact is a stream of text corresponding to a computer language (or other formal language), parsing consists of applying any of a variety of parsing algorithms (ad hoc, recursive descent, LL, LR, Packrat, Earley or other) to the source text (often broken into lexemes by another lower level parser called a "lexer") to verify the validity of the source language, and often to construct a parse tree representing the grammar productions used to tile the text.

The term can be applied more generally to analyzing any complex structure such as a binary data file or a graph.

57220 questions
295
votes
8 answers

How to read XML using XPath in Java

I want to read XML data using XPath in Java, so for the information I have gathered I am not able to parse XML according to my requirement. here is what I want to do: Get XML file from online via its URL, then use XPath to parse it, I want to create…
Adil Bhatty
  • 17,190
  • 34
  • 81
  • 118
291
votes
31 answers

Python/Json:Expecting property name enclosed in double quotes

I've been trying to figure out a good way to load JSON objects in Python. I send this json data: {'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}} to the backend where it will be…
raeX
  • 3,197
  • 2
  • 14
  • 21
286
votes
17 answers

How to parse a string to an int in C++?

What's the C++ way of parsing a string (given as char *) into an int? Robust and clear error handling is a plus (instead of returning zero).
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
281
votes
19 answers

How do I parse a string with a decimal point to a double?

I want to parse a string like "3.5" to a double. However, double.Parse("3.5") yields 35 and double.Parse("3.5", System.Globalization.NumberStyles.AllowDecimalPoint) throws a FormatException. Now my computer's locale is set to German, wherein a…
Legate
279
votes
25 answers

Parsing query strings on Android

Java EE has ServletRequest.getParameterValues(). On non-EE platforms, URL.getQuery() simply returns a string. What's the normal way to properly parse the query string in a URL when not on Java EE? It is popular in the answers to try and make your…
Will
  • 73,905
  • 40
  • 169
  • 246
278
votes
11 answers

How do I parse a string into a number with Dart?

I would like to parse strings like 1 or 32.23 into integers and doubles. How can I do this with Dart?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
277
votes
13 answers

Remove file extension from a file name string

If I have a string saying "abc.txt", is there a quick way to get a substring that is just "abc"? I can't do an fileName.IndexOf('.') because the file name could be "abc.123.txt" or something and I obviously just want to get rid of the extension…
meds
  • 21,699
  • 37
  • 163
  • 314
274
votes
6 answers

In Java, how do I parse XML as a String instead of a file?

I have the following code: DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile); How can I get it to parse XML contained within a String instead of a file?
Dewayne
  • 3,682
  • 3
  • 25
  • 23
269
votes
4 answers

What is the difference between LL and LR parsing?

Can anyone give me a simple example of LL parsing versus LR parsing?
267
votes
6 answers

How to parse a JSON string into JsonNode in Jackson?

It should be so simple, but I just cannot find it after being trying for an hour. I need to get a JSON string, for example, {"k1":v1,"k2":v2}, parsed as a JsonNode. JsonFactory factory = new JsonFactory(); JsonParser jp =…
fadmaa
  • 3,067
  • 3
  • 18
  • 14
259
votes
13 answers

Print JSON parsed object?

I've got a javascript object which has been JSON parsed using JSON.parse I now want to print the object so I can debug it (something is going wrong with the function). When I do the following... for (property in obj) { output += property + ': '…
Skizit
  • 43,506
  • 91
  • 209
  • 269
256
votes
7 answers

How to convert comma-delimited string to list in Python?

Given a string that is a sequence of several values separated by a commma: mStr = 'A,B,C,D,E' How do I convert the string to a list? mList = ['A', 'B', 'C', 'D', 'E']
O.rka
  • 29,847
  • 68
  • 194
  • 309
251
votes
10 answers

Java: parse int value from a char

I just want to know if there's a better solution to parse a number from a character in a string (assuming that we know that the character at index n is a number). String element = "el5"; String s; s = ""+element.charAt(2); int x =…
Noya
  • 3,879
  • 3
  • 26
  • 32
244
votes
19 answers

Convert JSON to Map

What is the best way to convert a JSON code as this: { "data" : { "field1" : "value1", "field2" : "value2" } } in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1,…
David Santamaria
  • 8,671
  • 7
  • 33
  • 43
241
votes
21 answers

Retrieving parameters from a URL

Given a URL like the following, how can I parse the value of the query parameters? For example, in this case I want the value of some_key . /some_path?some_key=some_value' I am using Django in my environment; is there a method on the request object…
niteshb
  • 2,599
  • 2
  • 17
  • 16