Kodi Community Forum
read data from XML file - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Scrapers (https://forum.kodi.tv/forumdisplay.php?fid=60)
+--- Thread: read data from XML file (/showthread.php?tid=354196)

read data from XML file - Gringopel - 2020-05-05

Hello everyone. I am making an addon to read files that are passed in an XML file. XML structure is very simple

Archivo XML

The addon.py where the error arises is this:
# -*- coding: utf-8 -*-
import sys
import xbmcgui
import xbmcplugin
import xbmc
import os
from urlparse import parse_qsl
from io import open
from bs4 import BeautifulSoup as bs

__url__ = sys.argv[0];
addon_handle  =  int ( sys . argv [ 1 ])

contenido =[]
archivo = open("D:\\Kodi_Listado_Completo.xml", mode="r", encoding="utf-8-sig")
lineas= archivo.readlines()
for i in range(len(lineas)):
    lineas.replace("\\ufeff", "")
contenido = "".join(lineas_modificadas)
documento = bs(contenido, "xml")
del lineas, lineas_modificadas, contenido

The addon.xml is this:[/i]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.lacibis" name="Lacibis" version="1.0.0" provider-name="julius">
    <import addon="xbmc.python" version="2.26.0"/>
    <import addon="plugin.video.youtube" version="6.7.0"/>
    <import addon="script.module.beautifulsoup4" version="4.6.2"/>    
  <extension point="xbmc.python.pluginsource" library="addon.py">
  <extension point="xbmc.addon.metadata">
    <description>Addon de Cine</description>

[i]The kodi.log file is as follows[/i]

From what I see it is a failure because KODI does not have a parse installed. I have tried to do the same with ElementTree.ettree but it doesn't give problems with script.module.abi dependency too.
I am a novice in this I would appreciate help. I have searched and tried different options but it doesn't work. Thank you

RE: read data from XML file - Roman_V_M - 2020-06-01

'xml' parser in BeautifulSoup4 uses lxml Python parser library. Since it is a binary library it is not included in Kodi. You can use either ElementTree or DOM parser that are included in Python standard library and do not require external dependencies.

Also this line:
lineas.replace("\\ufeff", "")
in your code does not make sense:
a) you are using an escape-encoded Unicode symbol inside a byte string so it is interpreted literally as a sequence of \, u, f, e, f and f English characters. Use Unicode literals (u'') for such cases.
b) you are opening a file in the text mode with utf-8-sig mode so the UTF-8 BOM byte (\uFEFF) is automatically skipped.
c) BOM is inserted only at the beginning of a file, not at each string, so no need to remove it from each string (which should be done in the the binary reading mode anyway).

RE: read data from XML file - zachmorris - 2020-07-08

My addon parses xml as well. I had used etree with success in the past:

import xml.etree.ElementTree as ET
my_ET = ET.parse(my_file).getroot())

I recently found another pure python script which you can just place in your addon structure and import. Its fast and generates a python dict you can work with directly: xmltodict


from contextlib import closing
from . import xmltodict
import xbmcvfs

with closing(xbmcvfs.File(my_file)) as content_file:
my_dict = xmltodict.parse(bytes(content_file.readBytes()))

RE: read data from XML file - Marie Black - 2020-12-03

One option is to build a target parser which just iterates through the nodes and 'triggers' when it sees a tag you care about.

RE: read data from XML file - Marie Black - 2020-12-07

Extraction of specific data from various website with tools https://mydataprovider.com . Receive the data in a structured CSV, XML or JSON file.

This forum uses Lukasz Tkacz MyBB addons.