Giter Site home page Giter Site logo

Please add toprettyxml about pyxb HOT 5 CLOSED

pabigot avatar pabigot commented on May 23, 2024
Please add toprettyxml

from pyxb.

Comments (5)

pabigot avatar pabigot commented on May 23, 2024

It's not particularly hard to do x.toDOM().toprettyxml() but yeah, I can see this might be worthwhile. I'll take a look after I deal with #26, but might not get to it for a while.

six.py: I didn't modify that line so you'd have to ask the authors, but it's probably just a leftover from it being a docstring in the past.

structures.py: fix queued. Thanks.

from pyxb.

zyv avatar zyv commented on May 23, 2024

I second that toprettyxml() would be nice to have!

from pyxb.

pabigot avatar pabigot commented on May 23, 2024

After considering this carefully I'm going to decline the enhancement. The problem is that the existing toxml() method combines arguments meant to control the conversion of the PyXB instance to a DOM structure, and to control the conversion of the DOM structure to XML text. It has only one argument that affects the DOM-to-XML step, and is essentially mandatory, so fits naturally as the first argument with the instance-to-DOM arguments which are rarely used following it.

In contrast toprettyxml() introduces two additional options specific to the DOM-to-XML phase, and places them before the mandatory encoding argument, which would make correct usage difficult when instance-to-DOM arguments are needed.

In short, at this point I sorta regret adding toxml() as a short-hand in the first place, so am sticking to my original response that x.toDOM().toprettyxml() is the recommended path.

from pyxb.

zyv avatar zyv commented on May 23, 2024

Maybe one could add an optional argument to toxml() as in pretty=False instead or that'd be problematic in some other way? Just wondering if you have also considered that...

from pyxb.

pabigot avatar pabigot commented on May 23, 2024

@zyv In fact, that's exactly how I started. But then, for pretty=True to be fully useful, I'd have to also add the indent and newl arguments which as I noted are in an inconsistent order relative to the existing encoding argument so they'd have to be keyword arguments too as there are already four parameters to toxml(). At that point I noticed that both functions are only available in minidom and PyXB isn't supposed to be restricted to a particular DOM implementation.

So trying to graft it in just got too messy: the best solution IMO is to convert to DOM, then use the native functions provided by the DOM implementation.

from pyxb.

Related Issues (20)

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.