Python Intermediate Tutorial #10 - XML Processing

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 47

  • @Dr.Cosmar
    @Dr.Cosmar 2 ปีที่แล้ว +2

    I stared at my code for a solid 5 mins trying to figure out what I screwed up (19:35) I created my own XML file, and by this point knew it was working just fine. Turns out...i did not capitalize the nodes in the XML file, but I did capitalize them in the code.
    It's amazing how "Name" is totally different from "name". No sarcasm, it's flexible.

  • @dmitriichashchin7566
    @dmitriichashchin7566 4 ปีที่แล้ว +11

    I cant see ur XML file in the description...

  • @jrgomez
    @jrgomez ปีที่แล้ว

    Very good explanation. Finally I understood how to deal with XML files.

  • @Aarabstrait
    @Aarabstrait 4 ปีที่แล้ว +9

    You just saved me a day of work ! Keep up the good content ... +1 sub 👍

    • @NeuralNine
      @NeuralNine  4 ปีที่แล้ว +1

      glad to hear that appreciate it :)

  • @TejNarayanan
    @TejNarayanan 2 ปีที่แล้ว +3

    Very well explained, thank you, can you please also suggest how to get the outputs as a separate dataframe/file (especially from the first method).

  • @Enteriel
    @Enteriel 3 ปีที่แล้ว

    BEST XML TUTORIAL FOR PYTHON THANK YOU !!!

  • @wanderborn.
    @wanderborn. 3 ปีที่แล้ว +1

    Nicely explained the concept of how to approach an XML file. Thanks for all those details.
    I searched your videos and couldn't find anything else about how to use XML files for data analysis. I mean: get needed attributes, nodes and export them into data-frame or CSV file for a further convenient use. There are plenty of 'simple' samples of XML to CSV transformations online, but none with a real 'complex' structured XML with attributes in sub-child and such.
    Would it be possible for you to create such 'in demand' tutorial?
    BTW, bought your book '3 in 1' and hope to learn a lot on data science.
    Cheers,

  • @nitishasthana03
    @nitishasthana03 2 ปีที่แล้ว

    How to extract values from a tag that has multiple child. For example, if the had multiple tags with then it only gives the first element not the second one.

  • @samp9418
    @samp9418 2 ปีที่แล้ว

    This is a really good tutorial. Thank you so much!

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt 4 ปีที่แล้ว +2

    Thank you so much, great video. It helped me a lot.

  • @federicobau8651
    @federicobau8651 3 ปีที่แล้ว +2

    Nice work man

  • @ali-om4uv
    @ali-om4uv 3 ปีที่แล้ว +2

    How are you supposed to know that these 3 functions are getting called in the original class? In your code it is not obvious that they are getting called at all.

  • @My1405NguyenThiThanh
    @My1405NguyenThiThanh ปีที่แล้ว

    Hi can you connect with database to create this xml ? I need do that for my task

  • @qaiszakry1975
    @qaiszakry1975 3 ปีที่แล้ว

    Hi. In the dom section of your tutorial when you used getElementByTagName you used the index [0] for each of the name, age, weight and height. May I ask you to explain that? I thought since we have a for loop which can take care of getting first index. Please explain

  • @anilsiddabathula3158
    @anilsiddabathula3158 4 ปีที่แล้ว +1

    Hi bro,
    Can yu tell how can i extract xml file in python to csv for data analysis

  • @prateeksarangi9187
    @prateeksarangi9187 2 ปีที่แล้ว +1

    Thanks Mate

  • @oritsemisanomare1941
    @oritsemisanomare1941 2 ปีที่แล้ว

    Thank you for this, it was actually easy to understand. But I replicated the last line where you wrote to the XML file, and it didn't work... help please.

  • @mstFPV
    @mstFPV 5 ปีที่แล้ว +1

    Can you make a vid of the top 5 best things you can make in Python?

    • @NeuralNine
      @NeuralNine  5 ปีที่แล้ว +2

      I will make some project videos and project idea videos in the future but currently I am working on the data science playlist! :)

  • @edgarsan71991
    @edgarsan71991 4 ปีที่แล้ว +1

    Awesome video I am impress just one question how to pass all this info to a data base or a mean a SQlite database?,,, very nice code again

    • @NeuralNine
      @NeuralNine  4 ปีที่แล้ว +1

      Have you watched the tutorial about databases? :)

    • @edgarsan71991
      @edgarsan71991 4 ปีที่แล้ว +2

      @@NeuralNine Yes of course it's very good, but I have another question how do you read more than 1 xml file? I hear that have to use the glob function like a said I'm starting.

    • @NeuralNine
      @NeuralNine  4 ปีที่แล้ว

      @@edgarsan71991 what do you mean by reading two files? You mean at the same time?

  • @PawanKumar-un7sk
    @PawanKumar-un7sk 2 ปีที่แล้ว +1

    need that xml document could u please provide us

  • @gabriellopezmontesinos2951
    @gabriellopezmontesinos2951 4 ปีที่แล้ว

    Nice video dude!!!

  • @Captinofthemudslayer
    @Captinofthemudslayer 4 ปีที่แล้ว

    this example is a little too simple could you do one with a more complex site like yahoo finance? How would i go about parsing the table on it

  • @lada2105apturbo
    @lada2105apturbo 3 ปีที่แล้ว +1

    very amazing! + 1 sub

  • @GFDNERFERSGAMING
    @GFDNERFERSGAMING 4 ปีที่แล้ว

    What if i wanted to count how many times each age pops up.

  • @excellentgyankosh
    @excellentgyankosh 4 ปีที่แล้ว

    From which college you learned all that.

    • @NeuralNine
      @NeuralNine  4 ปีที่แล้ว

      I didn't learn Python in college at all. But I currently study at the Technical University of Vienna

  • @Rahul-ff1vx
    @Rahul-ff1vx 4 ปีที่แล้ว

    This data you opened is like an html file

  • @jasperzanjani
    @jasperzanjani 3 ปีที่แล้ว +1

    how dare you use Notepad++ in a coding tutorial

  • @eliyaben9277
    @eliyaben9277 ปีที่แล้ว

    lol he forgot about the link

  • @sanjaybhat4260
    @sanjaybhat4260 4 ปีที่แล้ว

    This is not a intermideate level. Its a beginner level. I mean come on the xml you chose is sooo simple. Choose the words of your title carefully. otherwise you might invite some dislikes like i am disliking your video right now.

    • @test555channel
      @test555channel 3 ปีที่แล้ว +5

      if you are a begginer with python you dont start with xml, you start with if,strings etc.

    • @pedropaes902
      @pedropaes902 3 ปีที่แล้ว +6

      I've done a few paid python courses, from beginner to intermediate, and none of them taught how to work with xml. The file he used might be simple, but the python code itself isn't

    • @letsbye
      @letsbye 3 ปีที่แล้ว +3

      whats ur problem man, its a free content, u can go some where else, if you think you are too good here..!!

    • @sanjaybhat4260
      @sanjaybhat4260 3 ปีที่แล้ว

      @@letsbye free content doesn't mean u can mislead with titles. U r so naive that I don't even feel u r worth me spending my energy to make u understand.

    • @letsbye
      @letsbye 3 ปีที่แล้ว +2

      @@sanjaybhat4260 cheers, keep going now..!!

  • @jsmyers24151
    @jsmyers24151 ปีที่แล้ว

    For some reason, Python 3.10 is looking for a def __init__. I keep getting messages like this:
    Instance attribute current defined outside __init__:17
    Instance attribute name defined outside __init__:24
    Instance attribute age defined outside __init__:26
    Instance attribute weight defined outside __init__:28
    Instance attribute height defined outside __init__:30
    Instance attribute current defined outside __init__:41
    Of course, I understand that the number at the end of each line is the number of the line where the problem is being flagged, but I'm not understanding why Your code works and mine gives these error messages. And, that's not all of them. I'm also getting these error messages:
    C:\Users\jmyers\AppData\Local\Microsoft\WindowsApps\python3.10.exe "C:\Users\jmyers\PycharmProjects\Intermediate\XML Processing.py"
    Traceback (most recent call last):
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
    xml.parsers.expat.ExpatError: no element found: line 48, column 0
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File "C:\Users\jmyers\PycharmProjects\Intermediate\XML Processing.py", line 47, in
    parser.parse('data.xml')
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\xmlreader.py", line 127, in parse
    self.close()
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\expatreader.py", line 240, in close
    self.feed(b"", isFinal=True)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\expatreader.py", line 221, in feed
    self._err_handler.fatalError(exc)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\xml\sax\handler.py", line 38, in fatalError
    raise exception
    xml.sax._exceptions.SAXParseException: data.xml:48:0: no element found
    It's finding errors in lines of code that don't even exist in this program. What to do about that?
    But, yet, on top of all that (which is actually coming after these errors), I get the print out of the XML file. Weird!

    • @jsmyers24151
      @jsmyers24151 ปีที่แล้ว

      Okay. Once again, I found my problem. In the XML file, I forgot to close the group with . Once I did that, all my troubles seemed so far away. Sorry, had a Beatles moment, there. All of the errors disappeared.

  • @cuneytozkurt4867
    @cuneytozkurt4867 9 หลายเดือนก่อน

    hi, your video's so great. btw I'm trying to send to pandas but results are so bad as:
    0 1 NaN NaN
    1 NaN Jason Newsted NaN
    2 NaN NaN Bass Guitar
    3 NaN NaN NaN
    4 100 NaN NaN
    I don't know how can I get these to same row... My wrong kod is like:
    thank you...
    class GroupHandler(xml.sax.ContentHandler):
    def startElement(self, name: str, attrs):
    self.current = name
    self.current_data = {}
    def endElement(self, name):
    if name == "gl-cor:accountMainID":
    self.data.append({"NO": self.currentText})
    elif name == "gl-cor:accountMainDescription":
    self.data.append({"NAME":self.currentText})
    elif name == "gl-cor:accountSubDescription":
    self.data.append({"ENSTRUMENT":self.currentText})
    if name == "gl-cor:account":
    self.data.append(self.current_data)
    def characters(self, content):
    self.currentText = content.strip()
    def __init__(self):
    self.data = []