Code Monkey home page Code Monkey logo

xmltojson's Introduction

xmltojson


Python library and cli tool for converting XML to JSON

Downloads

Install

$ poetry add xmltojson

$ pip install xmltojson

Usage

Command line:

Converting an XML file and sending the output to STDOUT

$ xmltojson <filename.xml>

Send output to a file

$ xmltojson <filename.xml> -o <new_filename.json>

xmltojson can also read from STDIN

$ echo '<name>John</name>' | xmltojson --stdin

Library:

[1]: import xmltojson
[2]: with open('/path/to/file', 'r') as f:
...:     my_xml = f.read()
[3]: xmltojson.parse(my_xml)
'{"name": "John"}'

xmltojson's People

Contributors

mrasimzahid avatar shanahanjrs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xmltojson's Issues

What to do if line have "<" and ">" in text?

Hi.
This is crashing with "not well-formed (invalid token): line 1, column 67".
When I checked what is in inner html that I'm trying to parse, I find, that problems are in this line (yes, I modified it a bit, so it becomes user-friendly):

<h1 class="the_class"><a href="/the_link.html" title="The title is <So important>">And some text here</a></h1>
-----------------------------------------------------------------^

And error links us to where "is" ends.
If I'm correct, fail is because there, on page, someone named title with "<" and ">", so it triggers on it as on new tag and wants me to fix things that there should be something like:

...="The title is" <So

Or something like that.

Is there some way to make it think that anyway there should not be any tags inside "the quotes", even if there are some "<" and ">" inside?

PS At the moment I can just remove title part, but... how soon I will find that "<" and ">" are in part that I need?

ModuleNotFoundError: No module named 'utils'

Hi, #3 was closed and I didn’t find a way to re-open it, but the bug is still present.

$ pip3.11 show xmltojson
Name: xmltojson
Version: 2.0.2
Summary: A Python module and cli tool to quickly convert xml text or files into json
Home-page: https://github.com/shanahanjrs/xmltojson
Author: John Shanahan
Author-email: [email protected]
License: Apache-2.0
Location: /home/me/.local/lib/python3.11/site-packages
Requires: xmltodict
Required-by:

$ xmltojson --version
Traceback (most recent call last):
  File "/home/me/.local/bin/xmltojson", line 5, in <module>
    from xmltojson.scripts.cli import main
  File "/home/me/.local/lib/python3.11/site-packages/xmltojson/scripts/cli.py", line 7, in <module>
    import utils
ModuleNotFoundError: No module named 'utils'

ModuleNotFoundError: No module named 'utils'

Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import xmltojson
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xmltojson.py", line 23, in
import utils
ModuleNotFoundError: No module named 'utils'

Package can't be installed using pip

$ pip3 install xmltojson
Collecting xmltojson
  Using cached xmltojson-0.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/8t/b6yfjsvs5nqf44jcyfppm7bw0000gn/T/pip-build-eoo9ou1o/xmltojson/setup.py", line 2, in <module>
        import xmltojson
      File "/private/var/folders/8t/b6yfjsvs5nqf44jcyfppm7bw0000gn/T/pip-build-eoo9ou1o/xmltojson/xmltojson.py", line 21, in <module>
        import xmltodict
    ModuleNotFoundError: No module named 'xmltodict'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/8t/b6yfjsvs5nqf44jcyfppm7bw0000gn/T/pip-build-eoo9ou1o/xmltojson/

You can't import xmltodict in setup.py :) because it is not installed yet

I might be able to send a PR when I have time.

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.