Search Results

Search found 3176 results on 128 pages for 'parsing'.

Page 52/128 | < Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >

  • how to display a binary content of image/pdf in java script?

    - by Ka-rocks
    I have a binary content of image/pdf in java script variable downloaded from server. There will be indication server about the typr of the file. I have to display the content in respective file format. If it is image , i have to display the image. If it is a pdf, i have to open the content in pdf format. and so on. How to parse the binary content and display it? I have searched for it. But I couldn't find exact solution. I'm using jquery mobile framework. Pls help..

    Read the article

  • Remove parent xml tag based on child value

    - by cru3l
    For example, we have xml file with this format: <A> <B> <C></C> <D></D> <D></D> </B> </A> i need that: if all "D"-tags elements are empty, then we need to delete whole "A"-tag element and, of course, we need to do this with all "A"-tags in xml.

    Read the article

  • Communication between lexer and parser

    - by FredOverflow
    Every time I write a simple lexer and parser, I stumble upon the same question: how should the lexer and the parser communicate? I see four different approaches: The lexer eagerly converts the entire input string into a vector of tokens. Once this is done, the vector is fed to the parser which converts it into a tree. This is by far the simplest solution to implement, but since all tokens are stored in memory, it wastes a lot of space. Each time the lexer finds a token, it invokes a function on the parser, passing the current token. In my experience, this only works if the parser can naturally be implemented as a state machine like LALR parsers. By contrast, I don't think it would work at all for recursive descent parsers. Each time the parser needs a token, it asks the lexer for the next one. This is very easy to implement in C# due to the yield keyword, but quite hard in C++ which doesn't have it. The lexer and parser communicate through an asynchronous queue. This is commonly known under the title "producer/consumer", and it should simplify the communication between the lexer and the parser a lot. Does it also outperform the other solutions on multicores? Or is lexing too trivial? Is my analysis sound? Are there other approaches I haven't thought of? What is used in real-world compilers? It would be really cool if compiler writers like Eric Lippert could shed some light on this issue.

    Read the article

  • Simple XML parser in bison/flex

    - by user360872
    I would like to create simple xml parser using bison/flex. I don't need validation, comments, arguments, only <tag>value</tag>, where value can be number, string or other <tag>value</tag>. So for example: <div> <mul> <num>20</num> <add> <num>1</num> <num>5</num> </add> </mul> <id>test</id> </div> If it helps, I know the names of all tags that may occur. I know how many sub-tag can be hold by given tag. Is it possible to create bison parser that would do something like that: - new Tag("num", 1) // tag1 - new Tag("num", 5) // tag2 - new Tag("add", tag1, tag2) // tag3 - new Tag("num", 20) // tag4 - new Tag("mul", tag4, tag3) ... - root = top_tag Tag & number of sub-tags: num: 1 (only value) str: 1 (only value) add | sub | mul | div: 2 (num | str | tag, num | str | tag) Could you help me with grammar to be able to create AST like given above?

    Read the article

  • How to parse (infinite) nested object notation?

    - by kyogron
    I am currently breaking my head about transforming this object hash: "food": { "healthy": { "fruits": ['apples', 'bananas', 'oranges'], "vegetables": ['salad', 'onions'] }, "unhealthy": { "fastFood": ['burgers', 'chicken', 'pizza'] } } to something like this: food:healthy:fruits:apples food:healthy:fruits:bananas food:healthy:fruits:oranges food:healthy:vegetables:salad food:healthy:vegetables:onions food:unhealthy:fastFood:burgers food:unhealthy:fastFood:chicken food:unhealthy:fastFood:pizza In theory it actually is just looping through the object while keeping track of the path and the end result. Unfortunately I do not know how I could loop down till I have done all nested. var path; var pointer; function loop(obj) { for (var propertyName in obj) { path = propertyName; pointer = obj[propertyName]; if (pointer typeof === 'object') { loop(pointer); } else { break; } } }; function parse(object) { var collection = []; }; There are two issues which play each out: If I use recurse programming it looses the state of the properties which are already parsed. If I do not use it I cannot parse infinite. Is there some idea how to handle this? Regards

    Read the article

  • How can I know whether my C++ string variable is a number or not

    - by user342580
    I have a string of class string string str; how can I check if it is a number or not, str can only have 3 possible types described below like abcd or a number like 123.4 or a number with a parenthesis attach to the end it for example 456) note the parenthesis at the end of "str" is the only possible combination of number and none number where the bottom two are considered valid numbers, I know I could use lexical_cast if only the first 2 cases occur, but how about considering all 3 possible cases to occur? I don't need to do anything fancy with str, I just need to know whether it is a valid number as I described

    Read the article

  • More elegant way to parse inline variables in strings

    - by Tom
    Currently I have this: function parse_string($string, $variables){ extract($variables); return eval('return "'. addcslashes($string, '"') .'";'); } So I can input this string: 'Hi {$name}, my name is {$own_name}' Together with this array: array('name' => 'John', 'own_name' => 'Tom') And get this back: 'Hi John, my name is Tom'   I've never liked this eval() approach but it works and it's fast (faster than regex at least). Question: Is there a more elegant way to do this (faster than using regex) in PHP5?

    Read the article

  • How do I parse an HTML website using Perl?

    - by Nano HE
    Could you please give me some suggestions on how to parse HTML in Perl? I plan to parse the keywords(including URL links) and save them to a MySQL database. I am using Windows XP. Also, do I first need to download some website pages to the local hard drive with some offline Explorer tool? If I do, could you point me to a good download tool?

    Read the article

  • how to load data and store the data from a file using numpy

    - by Charlie Epps
    I have the following file like this: 2 qid:1 1:0.32 2:0.50 3:0.78 4:0.02 10:0.90 5 qid:2 2:0.22 5:0.34 6:0.87 10:0.56 12:0.32 19:0.24 20:0.55 ... he structure is follwoing like that: output={} rel=2 qid=1 features={} # the feature list "1:0.32 2:0.50 3:0.78 4:0.02 10:0.90" output.append([rel,qid,features]) ... How can I write my python code to load the data, thanks

    Read the article

  • Problem with skipping empty cells while importing data from .xlsx file in asp.net c# application

    - by Eedoh
    Hi to all. I have a problem with reading .xlsx files in asp.net mvc2.0 application, using c#. Problem occurs when reading empty cell from .xlsx file. My code simply skips this cell and reads the next one. For example, if the contents of .xlsx file are: FirstName LastName Age John 36 They will be read as: FirstName LastName Age John 36 Here's the code that does the reading. private string GetValue(Cell cell, SharedStringTablePart stringTablePart) { if (cell.ChildElements.Count == 0) return string.Empty; //get cell value string value = cell.ElementAt(0).InnerText;//CellValue.InnerText; //Look up real value from shared string table if ((cell.DataType != null) && (cell.DataType == CellValues.SharedString)) value = stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText; return value; } private DataTable ExtractExcelSheetValuesToDataTable(string xlsxFilePath, string sheetName) { DataTable dt = new DataTable(); using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(xlsxFilePath, true)) { //Access the main Workbook part, which contains data WorkbookPart workbookPart = myWorkbook.WorkbookPart; WorksheetPart worksheetPart = null; if (!string.IsNullOrEmpty(sheetName)) { Sheet ss = workbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == sheetName).SingleOrDefault<Sheet>(); worksheetPart = (WorksheetPart)workbookPart.GetPartById(ss.Id); } else { worksheetPart = workbookPart.WorksheetParts.FirstOrDefault(); } SharedStringTablePart stringTablePart = workbookPart.SharedStringTablePart; if (worksheetPart != null) { Row lastRow = worksheetPart.Worksheet.Descendants<Row>().LastOrDefault(); Row firstRow = worksheetPart.Worksheet.Descendants<Row>().FirstOrDefault(); if (firstRow != null) { foreach (Cell c in firstRow.ChildElements) { string value = GetValue(c, stringTablePart); dt.Columns.Add(value); } } if (lastRow != null) { for (int i = 2; i <= lastRow.RowIndex; i++) { DataRow dr = dt.NewRow(); bool empty = true; Row row = worksheetPart.Worksheet.Descendants<Row>().Where(r => i == r.RowIndex).FirstOrDefault(); int j = 0; if (row != null) { foreach (Cell c in row.ChildElements) { //Get cell value string value = GetValue(c, stringTablePart); if (!string.IsNullOrEmpty(value) && value != "") empty = false; dr[j] = value; j++; if (j == dt.Columns.Count) break; } if (empty) break; dt.Rows.Add(dr); } } } } } return dt; }

    Read the article

  • LALR(1) or GLR on Windows - Alternatives to Bison++ / Flex++ that are current?

    - by mrjoltcola
    I have been using the same version of bison++ (1.21-8) and flex++ (2.3.8-7) since 2002. I'm not looking for an alternative to LALR(1) or GLR at this time, just looking for the most current options. Is anyone aware of any later ports of these than the original that aren't Cygwin dependent? What are other folks using in Windows environments for C++ compiler development (besides ANTLR or Boost.spirit)? Commercial options are ok, if you have firsthand experience. I do need to compile on Linux as well.

    Read the article

  • relace double quotes to parse JSON in PHP

    - by hunt
    hi, i have following json format { "status": "ACTIVE", "result": false, "isworking": false, "margin": 1, "employee": { "111": { "val1": 5.7000000000000002, "val2": "9/2", "val3": 5.7000000000000002 }, "222": { "val1": 31.550000000000001, "val2": "29/1", "val3": 31.550000000000001 } } } how the problem is when i am trying to decode above json response in php using json_decode($res,true) { true param for associative array } i am getting following result as few fields like "result":false is not "result":"false" i.e. at many of the places doubles quotes are missing in values of json. see in val1 and val3 fields resultant data after decoding in php (associative array) Array ( [status] = ACTIVE [result] = [isworking] = [margin] = 1 [employee] = Array ( [111] = Array ( [val1] = 5.7 [val2] = 9/2 [val3] = 5.7 ) [222] = Array ( [val1] = 31.55 [val2] = 29/1 [val3] = 31.55 ) ) ) please help me on how would i insert double quotes in values ? Thanks

    Read the article

  • SimpleXMLElement empty object

    - by Mike
    Hi, I am trying to parse an xml file using XmlReader but although I am getting a return from the xml file for the (commission) node for some reason I am getting an empty SimpleXMLElement Object returned as well. I don't know if its something to do with while loop,switch or something I missed in the parse setup. This is the xml file I am trying to read from, as you can see there is only 1 result returned: <?xml version="1.0" encoding="UTF-8"?> <cj-api> <commissions total-matched="1"> <commission> <action-status> new </action-status> <action-type> lead </action-type> <aid> 10730981 </aid> <commission-id> 1021015513 </commission-id> <country> </country> <event-date> 2010-05-08T08:08:55-0700 </event-date> <locking-date> 2010-06-10 </locking-date> <order-id> 345007 </order-id> <original> true </original> <original-action-id> 787692438 </original-action-id> <posting-date> 2010-05-08T10:01:22-0700 </posting-date> <website-id> 3201921 </website-id> <cid> 2815954 </cid> <advertiser-name> SPS EurosportBET </advertiser-name> <commission-amount> 0 </commission-amount> <order-discount> 0 </order-discount> <sid> 0 </sid> <sale-amount> 0 </sale-amount> </commission> </commissions> </cj-api> This is my parser: <?php // read $response (xml feed) $file = "datafeed.xml"; $xml = new XMLReader; $xml->open($file); // loop to read in data while ($xml->read()) { switch ($xml->name) { // find the parent node for each commission payment case 'commission': // initalise xml parser $dom = new DomDocument(); $dom_node = $xml ->expand(); $element = $dom->appendChild($dom_node); $dom_string = $dom->saveXML($element); $commission = new SimpleXMLElement($dom_string); // read in data $action_status = $commission->{'action-status'}; $action_type = $commission->{'action-type'}; $aid = $commission->{'aid'}; $commission_id = $commission->{'commission-id'}; $country = $commission->{'country'}; $event_date = $commission->{'event-date'}; $locking_date = $commission->{'locking-date'}; $order_id = $commission->{'order-id'}; $original = $commission->{'original'}; $original_action_id = $commission->{'original_action-id'}; $posting_date = $commission->{'posting-date'}; $website_id = $commission->{'website-id'}; $cid = $commission->{'cid'}; $advertiser_name = $commission->{'advertiser-name'}; $commission_amount = $commission->{'commission-amount'}; $order_discount = $commission->{'order-discount'}; $sid = $commission->{'sid'}; $sale_amount = $commission->{'sale-amount'}; print_r($aid); break; } } ?> The result is : SimpleXMLElement Object ( [0] => 10730981 ) SimpleXMLElement Object ( ) Why is it returning the second object: SimpleXMLElement Object ( ) and what do I need to do correct it? Thanks.

    Read the article

  • Checking when two headers are included at the same time.

    - by fortran
    Hi, I need to do an assertion based on two related macro preprocessor #define's declared in different header files... The codebase is huge and it would be nice if I could find a place to put the assertion where the two headers are already included, to avoid polluting namespaces unnecessarily. Checking just that a file includes both explicitly might not suffice, as one (or both) of them might be included in an upper level of a nesting include's hierarchy. I know it wouldn't be too hard to write an script to check that, but if there's already a tool that does the job, the better. Example: file foo.h #define FOO 0xf file bar.h #define BAR 0x1e I need to put somewhere (it doesn't matter a lot where) something like this: #if (2*FOO) != BAR #error "foo is not twice bar" #endif Yes, I know the example is silly, as they could be replaced so one is derived from the other, but let's say that the includes can be generated from different places not under my control and I just need to check that they match at compile time... And I don't want to just add one include after the other, as it might conflict with previous code that I haven't written, so that's why I would like to find a file where both are already present. In brief: how can I find a file that includes (direct or indirectly) two other files? Thanks!

    Read the article

  • Perl: How do I extract certain bits from a byte and then covert these bits to a hex value?

    - by Siegfried Hepp
    I need to extract certain bits of a byte and covert the extract bits back to a hex value. Example (the value of the byte is 0xD2) : 76543210 bit position 11010010 is 0xD2 Bit 0-3 defines the channel which is 0010b is 0x2 Bit 4-5 defines the controller which is 01b is 0x1 Bit 6-7 defines the port which is 11b is 0x3 I somehow need to get from the byte is 0xD2 to channel is 0x2, controller is 0x1, port is 0x3 I googled allot and found the functions pack/unpack, vec and sprintf. But I'm scratching by head how to use the functions to achieve this. Any idea how to achieve this in Perl ?

    Read the article

  • Inheriting XML files and modifying values

    - by Veehmot
    This is a question about concept. I have an XML file, let's call it base: <base id="default"> <tags> <tag>tag_one</tag> <tag>tag_two</tag> <tag>tag_three</tag> </tags> <data> <data_a>blue</data_a> <data_b>3</data_b> </data> </base> What I want to do is to be able to extend this XML in another file, modifying individual properties. For example, I want to inherit that file and make a new one with a different data/data_a node: <base id="green" import="default"> <data> <data_a>green</data_a> </data> </base> So far it's pretty simple, it replaces the old data/data_a with the new one. I even can add a new node: <base id="ext" import="default"> <moredata> <data>extended version</data> </moredata> </base> And still it's pretty simple. The problem comes when I want to delete a node or deal with XML Lists (like the tags node). How should I reference a particular index on a list? I was thinking doing something like: <base id="diffList" import="default"> <tags> <tag index="1">this is not anymore tag_two</tag> </tags> </base> And for deleting a node / array index: <base id="deleting" import="default"> <tags> <tag index="2"/> </tags> <data/> </base> <!-- This will result in an XML containing these values: --> <base> <tag>tag_one</tag> <tag>tag_two</tag> </base> But I'm not happy with my solutions. I don't know anything about XSLT or other XML transformation tools, but I think someone must have done this before. The key goal I'm looking for is ease to write the XML by hand (both the base and the "extended"). I'm open to new solutions besides XML, if they are easy to write manually. Thanks for reading.

    Read the article

  • How do I process the largest match first in PHP?

    - by animuson
    Ok, so I tried searching around first but I didn't exactly know how to word this question or a search phrase. Let me explain. I have data that looks like this: <!-- data:start --> <!-- 0:start --> <!-- 0:start -->0,9<!-- 0:stop --> <!-- 1:start -->0,0<!-- 1:stop --> <!-- 2:start -->9,0<!-- 2:stop --> <!-- 3:start -->9,9<!-- 3:stop --> <!-- 4:start -->0,9<!-- 4:stop --> <!-- 0:stop --> <!-- 1:start --> <!-- 0:start -->1,5<!-- 0:stop --> <!-- 1:start -->1,6<!-- 1:stop --> <!-- 2:start -->3,6<!-- 2:stop --> <!-- 3:start -->3,8<!-- 3:stop --> <!-- 4:start -->4,8<!-- 4:stop --> <!-- 1:stop --> <!-- 2:start --> <!-- 0:start -->0,7<!-- 0:stop --> <!-- 1:start -->1,7<!-- 1:stop --> <!-- 2:stop --> <!-- data:stop --> So it's basically a bunch of points. Here is the code I'm currently using to try and parse it so that it would create an array like so: Array ( 0 => Array ( 0 => "0,9", 1 => "0,0", 2 => "9,0", 3 => "9,9", 4 => "0,9" ), 1 => Array ( 0 => "1,5", 1 => "1,6", 2 => "3,6", 3 => "3,8", 4 => "4,8" ), 2 => Array ( 0 => "0,7", 1 => "1,7" ) ) However, it is returning an array that looks like this: Array ( 0 => "0,9", 1 => "0,0", 2 => "9,0" ) Viewing the larger array that I have on my screen, you see that it's setting the first instance of that variable when matching. So how do I get it to find the widest match first and then process the insides. Here is the function I am currently using: function explosion($text) { $number = preg_match_all("/(<!-- ([\w]+):start -->)\n?(.*?)\n?(<!-- \\2:stop -->)/s", $text, $matches, PREG_SET_ORDER); if ($number == 0) return $text; else unset($item); foreach ($matches as $item) if (empty($data[$item[2]])) $data[$item[2]] = $this->explosion($item[3]); return $data; } I'm sure it will be something stupid and simple that I've overlooked, but that just makes it an easy answer for you I suppose.

    Read the article

  • How to resolve parse error in Splint

    - by Thi
    Splint is not continuing it's checking after finding parse errors. I've tried with +trytorecover option also but no change. Please let me know on how to use +trytorecover to make Splint attempt to continue after a parse error. Here is what I'm receiving, 161: splint +trytorecover spy.c Splint 3.1.1 --- 19 Jul 2006 spy.c:41:12: Parse Error: Non-function declaration: byte_4 : int. Attempting to continue. spy.c:41:12: Cannot recover from parse error. *** Cannot continue.

    Read the article

  • Loading data from file to Vector structure

    - by owca
    I'm trying to parse through fixed-width formatted file extracting x,y values of points from it, and then storing them in int[] array inside a Vector. Text file looks as follows : 0006 0015 0125 0047 0250 0131 That's the code : Vector<int[]> vc = new Vector<int[]>(); try { BufferedReader file = new BufferedReader(new FileReader("myfile.txt")); String s; int[] vec = new int[2]; while ((s = file.readLine()) != null) { vec[0] = Integer.parseInt(s.substring(0, 4).trim()); vec[1] = Integer.parseInt(s.substring(5, 8).trim()); vc.add(vec); } file.close(); } catch (IOException e) { } for(int i=0; i<vc.size(); i++){ for(int j=0; j<2; j++){ System.out.println(vc.elementAt(i)[j]); } } But the output shows only last line. 250 131 250 131 250 131 Should I somehow use Vector.nextElement() here to get all my data ?

    Read the article

  • Removing HTML from a Java String

    - by Mason
    Is there a good way to remove HTML from a Java string? A simple regex like replaceAll("\\<.*?>","") will work, but things like &amp; wont be converted correctly and non-HTML between the two angle brackets will be removed (ie the .*? in the regex will disappear).

    Read the article

  • HowTo parse numbers from string with BOOST methods?

    - by mosg
    Problem: Visual C++ 10 project (using MFC and Boost libraries). In one of my methods I'm reading simple test.txt file. Here is what inside of the file (std::string): 12 asdf789, 54,19 1000 nsfewer:22!13 Then I'm reading it and I have to convert all digits to int only with boost methods. For example, I have a list of different characters which I have to parse: ( ’ ' ) ( [ ], ( ), { }, ? ? ) ( : ) ( , ) ( ! ) ( . ) ( - ) ( ? ) ( ‘ ’, “ ”, « » ) ( ; ) ( / ) And after conversation I must have some kind of a massive of int's values, like this one: 12,789,54,19,1000,22,13 Maybe some one already did this job? PS. I'm new for boost. Thanks!

    Read the article

  • How to parse string from column in csv in Powershell

    - by user1445620
    I have a csv configured as such: PK,INV_AMT,DATE,INV_NAME,NOTE 1,123.44,634,asdfljk,TEST 12OING 06/01/2010 DATE: 04/10/2012 2,123.44,634,wet aaa,HI HOW ARE YOU 11.11 DATE: 01/01/2011 3,123.44,634,dfssdsdfRR,LOOK AT ME NOW….HI7&&& DATE: 06/11/1997 4,123.44,634,asdfsdgg,LOOK AT ME NOW….HI7&&& DATE: 03-21-2097 5,123.44,634,45746345,LOOK AT ME NOW….HI7&&& DATE: 02/18/2000 How can I parse the date after the string "DATE:" in the note column using powershell? For example, the first row has the string "TEST 12OING 06/01/2010 DATE: 04/10/2012" in the note column. I need to parse '04/10/2012' out of that row. I would like to be able to read from a csv file such as the one above and parse out that date and add it as a new column in the csv file. Thanks for any help.

    Read the article

  • Is a switch statment ok for 30 or so conditions?

    - by DeanMc
    I am in the final stages of creating an MP4 tag parser in .Net. For those who have experience with tagging music you would be aware that there are an average of 30 or so tags. If tested out different types of loops and it seems that a switch statement with Const values seems to be the way to go with regard to catching the tags in binary. The switch allows me to search the binary without the need to know which order the tags are stored or if there are some not present but I wonder if anyone would be against using a switch statement for so many conditionals. Any insight is much appreciated.

    Read the article

< Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >