The Easiest Way to Parse XML with JavaScript

  Рет қаралды 37,666

dcode

Жыл бұрын

In this video, I'll show you how easy it is to parse XML strings using JavaScript - no libraries or frameworks are required to do this 🙂
Towards the end I'll also show a Fetch example where an XML document is retrieved from a file and then parsed to access the data within it.
For your reference, check this out:
developer.mozilla.org/en-US/docs/Web/API/DOMParser
🏫 My Udemy Courses - www.udemy.com/user/domenic-corso/
🎨 Download my VS Code theme - marketplace.visualstudio.com/items?itemName=dcode.dcode-theme
💜 Join my Discord Server - discord.gg/TXMQyvbpcA
🐦 Find me on Twitter - dcodeyt
💸 Support me on Patreon - www.patreon.com/dcode
📰 Follow me on DEV Community - dev.to/dcodeyt
📹 Join this channel to get access to perks - kzfaq.info/love/jX0FtIZBBVD3YoCcxnDC4gjoin
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript

Пікірлер: 34
@ahmedAltariqi
@ahmedAltariqi Жыл бұрын
You're awesome! Thank you so much for this great tutorial -- because of you now I don't have to ttml-to-json python package, and my code runs way much faster!
@crownkiwifactoryNZ
@crownkiwifactoryNZ 9 ай бұрын
Thank you for the tutorial, it helps me a lot at work. ❤
@ubermensch-mne
@ubermensch-mne Жыл бұрын
Useful video, thanks.
@sondrepedersen7919
@sondrepedersen7919 Жыл бұрын
Wow, exactly what I needed! I was about to go crazy with some regex, but I think you just saved me a lot of pain
@dcode-software
@dcode-software Жыл бұрын
Absolutely! I'm glad to hear that I prevented you from going down that path (it would have been a pain)
@thierrysandre440
@thierrysandre440 Жыл бұрын
Excellent !👍
@arnosolo2008
@arnosolo2008 10 ай бұрын
Thank you so much! 😸
@mariumbegum7325
@mariumbegum7325 Жыл бұрын
great video!
@cutefunnypets3164
@cutefunnypets3164 Жыл бұрын
keep up the awesome work bro!💪
@dcode-software
@dcode-software Жыл бұрын
Thanks, you too!
@alvarobyrne
@alvarobyrne Жыл бұрын
Humble and humbling DOMParser, nice, didn't know,
@dcode-software
@dcode-software Жыл бұрын
Awesome 😎
@ivanetinajero
@ivanetinajero Жыл бұрын
Great content. How can I ask If an element exists inside the XML document? Thanks for this great an easy tutorial.
@kipo44
@kipo44 Жыл бұрын
thanks, bro
@Dhiraj_Chaudhari
@Dhiraj_Chaudhari 7 ай бұрын
Can you please tell how to parse any content data from dynamic html file
@SuviTuuliAllan
@SuviTuuliAllan Жыл бұрын
Is it true that text/xml is parsed as US-ASCII while application/xml is parsed as UTF-8?
@zegarek840525
@zegarek840525 Жыл бұрын
What about big file?? Is there in 2023 native SAX parser??
@xawoo6655
@xawoo6655 8 ай бұрын
🦩 Hello everyone! 🟢 00:00 - introduction 🟢 01:00 - handle xml from string 🟢 01:40 - use of DOM parser 🟢 03:24 - element navigation 🟢 05:20 - handle xml from fetch request
@aleksandrkobelev8868
@aleksandrkobelev8868 Жыл бұрын
If you have error put in your xml
@mohamedsimo6021
@mohamedsimo6021 Жыл бұрын
Can you please do a video about how to create like vuejs library I mean reactivity etc I watched the your spa video and I like it .
@khamzateedira9021
@khamzateedira9021 Жыл бұрын
Can you do somme video about react
@tamerlone5094
@tamerlone5094 Жыл бұрын
When I paste in the xml as he has it (1st part of the video), the editor throws an error and doesn't like the XML pasted. Anyone else have this problem?
@danielcook237
@danielcook237 6 ай бұрын
Yeah I did, I was using ' instead of ` .
@vijayjeee8806
@vijayjeee8806 Жыл бұрын
@christianromero7982
@christianromero7982 Жыл бұрын
i can not split my string literal across multiple lines
@Konslufius
@Konslufius Жыл бұрын
Where were you like 2 months ago??
@dcode-software
@dcode-software Жыл бұрын
Were you looking to parse XML 2 months ago? 😆
@ReginaldBarclay-tr2cp
@ReginaldBarclay-tr2cp 11 күн бұрын
CONST NOT CUN+S. PARSE NOT PAWS, rotfl (or WOTFL for you). great tutorial. just takes a few minutes to figure it out. fun
@madalabhavyasri-nr6pr
@madalabhavyasri-nr6pr Жыл бұрын
How to convert this XML string to json??
@weixiaolisa
@weixiaolisa 11 ай бұрын
function xml2json(xml) { if (xml.children.length === 0) return xml.textContent.trim() const obj = {} for (let child of xml.children) { const name = child.nodeName if (obj[name] === undefined) obj[name] = xml2json(child) else { if (!Array.isArray(obj[name])) obj[name] = [obj[name]] obj[name].push(xml2json(child)) } } return obj }
@erturkyorulmaz7376
@erturkyorulmaz7376 Жыл бұрын
Verry helpful channel!.. 👏 Do you have a link for codes? Or shall I write it! :) 🌹
@dcode-software
@dcode-software Жыл бұрын
Hey, thank you! I assume you have some XML somewhere else but if not there's plenty of XML examples online - any of them should work 😎👍
@erturkyorulmaz7376
@erturkyorulmaz7376 Жыл бұрын
@@dcode-software Hi! I mean the JS code you write in your videos. But, no prblem I can write again. Thank you for your kindness and videos that help us. 👋
@fgscaglioni
@fgscaglioni 10 ай бұрын
Excelente!! Me ajudou muito!
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 35 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН