Git Product home page Git Product logo

Comments (3)

hay avatar hay commented on September 15, 2024

Maybe you're directly feeding the URL to Knead()? Unfortunately dataknead doesn't do anything with URLs, you need to use them in tandem with a HTTP request library, like requests. This works for with me (converting to JSON):

from dataknead import Knead
import requests

req = requests.get("http://www.nvon-biologie-itembank.nl/xml/nvon.xml")
Knead(req.text, parse_as = "xml").write("data.json", indent = 4)

from dataknead.

liekeverhelst avatar liekeverhelst commented on September 15, 2024

Sorry I did not explain well. The file mentioned was downloaded before I loaded it into Knead.
So:
from dataknead import Knead
file_in = "nvon.xml"
file_out = "test.csv"

Knead(file_in).write(file_out)

The output test.csv on my machine reads:
metadata

"OrderedDict([('subject', [OrderedDict([('text', 'Ademhaling = ah'), ('subsubject', [OrderedDict([('text', 'ademhaling - bloed = ab')]), OrderedDict([('text', 'ademhaling - bloed alcohol = aba')]) etcetera

from dataknead.

hay avatar hay commented on September 15, 2024

Ah yes, now i get it. Unfortunately, this is expected behaviour. CSV is inherently a two-dimensional format (rows and columns), while XML and JSON are nested. No library is going to solve that for you. You either need to write a mapping on how the nested data is going to be transformed to CSV, or use a nested structure like JSON or XML.

Knead does give you a couple of utilities for that, but mostly you'll want to use Python features like list comprehensions. Note that you can do:

data = Knead(in_file).data()

To get your input XML data as a native Python data structure. After that you can do something like:

Knead(data).write(out_file)

from dataknead.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.