-1

I'm trying to upload a HTM file using in Vue. The data is actually a styled table using , , etc...

My question is that, is it possible to filter out the tabulated data in HTM into other forms of data, say JSON? - Picture below (taken from browser elements of the htm) - Basically I just want to filter out html syntaxes and just retrieve the data.

enter image description here

Chiu
  • 11
  • 3
  • sure, you could process the rows, each row could have the values of the cells in an array ... so you'd end up with a 2d array like `[[row1-cell1, row1-cell2,.....],[r2c1, r2c2,....], ...]` – Jaromanda X Sep 19 '22 at 06:02
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+parse+html+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Sep 19 '22 at 06:04
  • https://stackoverflow.com/questions/61169217/vue-import-html-from-local-file – mplungjan Sep 19 '22 at 06:05
  • 1
    thing is, this is vue ... how was the table created in the first place? – Jaromanda X Sep 19 '22 at 06:07
  • @Chiu After upload HTML file, You mean you are getting HTML content as a response from an API call and you want to just filtered out the html syntaxes ? If yes, you can achieve that by using `RegEx` and remove the HTML syntaxes. – Debug Diva Sep 19 '22 at 06:52
  • @JaromandaX it is a HTM file being uploaded to a website created using Vue. – Chiu Sep 20 '22 at 03:20
  • @RohìtJíndal no, basically it's a HTML file generated from a machine (which in turn is a table of tabulated data - as shown in the pic), the file will be uploaded to a cloud database but before that I am going to process the data in json (only thing is the file is in html, but if you can filter out the html syntaxes with `RegEx` - should be ok) Thanks though – Chiu Sep 20 '22 at 03:23
  • You should be able to use a DOM parser. There is one built into your browser: `new DOMParser().parseFromString(htmlFileAsString, 'text/html')`. If you're on a Node.JS server you can use an npm package like [jsdom](https://www.npmjs.com/package/jsdom). – Andria Sep 20 '22 at 03:40

1 Answers1

0

Solution: use RegEx to filter HTML syntaxes.

Similar post: Regular expression to remove HTML tags from a string

Chiu
  • 11
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 23 '22 at 07:57