473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

how to print newline in xml?

I currently use xml.dom.minidom and ext to create a dom-tree which I
would write to an xml-file.
My intention is to create something like this:

<Robot> <!-- armar3 -->
<Joint>
</Joint>

<Joint>
</Joint>
</Robot>

but I didn't find any possibility either to put comment directly behind
a tag nor did I found how to put a new line like in example between the
two joints. The reason why I'm trying to achieve this: the file should
be easy to read for a human...

now I can just print the upper document like this:

<!-- armar3 -->
<Robot>
<Joint>
</Joint>
<Joint>
</Joint>
</Robot>

which is already not very readable - but it becomes even worse along
with increasing number of comments

May 30 '06 #1
7 4018
"an************@googlemail.com" <an************@googlemail.com> wrote:
which is already not very readable - but it becomes even worse along
with increasing number of comments


How about:

<robot>
<description>armar3</description>
:
:
</robot>

XML editor + xpath makes this way more easier to use by humans compared to
normal comments. Also, if you declare several of comment elements
(summary, description, author, etc.) you can auto generate documentation
etc.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
May 31 '06 #2
Thank you for a possible solution, but it's not what I'm looking for,
cause something like <!-- comment --> would look quite similar... for
big elements like robot it would be ok to use comment as a child of
element - but imagine I'd like to comment transformation:

<transformation x="0" y="0" z="0"/> I wouldn't like to make this
element parent of a description - it is not nice - I have lots of such
elements.

It is important that a user after having a glance at the document is
able to quickly find and change some values. I don't want to bother him
with reading documentation nodes - but if he needs - they should be
there... the only possible solution I can think of would be:

<Robot>
<verbose mode="enabled"/> <!-- enabled, disabled
-->
<CollisionChecker type="vcollide"/> <!-- possible values for
type: vcollide, (nyi: disabled) -->
<Visualisation mode="3DModel"/> <!-- posiible values for
mode: 3DModel, (nyi: disabled, line) -->

<!-- <Offset eulerX="-90" eulerZ="90"/> -->

<RootJoint> <!-- the one and only
root joint -->
<Name value="Armar3"/> <!-- name of this joint
-->
<DH> <!-- Denavit Hartenberg
parameters -->
<alpha value="0"/>
</DH>

<ID value="0"/> <!-- unique ID of this
joint -->
<ChildNodes childID="1"/> <!-- all child joints of
this joint -->
</RootJoint>

<ChildJoint>
<Name value="Platform"/>
<JointTransformation>
<RotationAxis X="0" Y="0" Z="1" INIT="0"/>
<TranslationFromParent X="0" Y="0" Z="0"/>
</JointTransformation>
<Visualisation> <!-- visualisation
settings for this joint -->
<IVModel file="model/platform.iv"/> <!-- filename of full 3d
model -->
</Visualisation>
<ID value="1"/> <!-- unique ID of this
joint -->
<ChildNodes childID="2"/> <!-- all child joints of
this joint -->
</ChildJoint>
How about:

<robot>
<description>armar3</description>
:
:
</robot>

XML editor + xpath makes this way more easier to use by humans compared to
normal comments. Also, if you declare several of comment elements
(summary, description, author, etc.) you can auto generate documentation
etc.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html


Jun 1 '06 #3
"an************@googlemail.com" <an************@googlemail.com> wrote:
Thank you for a possible solution, but it's not what I'm looking for,
cause something like <!-- comment --> would look quite similar... for
big elements like robot it would be ok to use comment as a child of
element - but imagine I'd like to comment transformation:

<transformation x="0" y="0" z="0"/> I wouldn't like to make this
element parent of a description - it is not nice - I have lots of such
elements.
Then add the comment to the parent of transformation, or an other option
might be:

<transformation x="0" y="0" z="0" description="some description"/>
It is important that a user after having a glance at the document is
able to quickly find and change some values. I don't want to bother
him with reading documentation nodes - but if he needs - they should
be there... the only possible solution I can think of would be:

<Robot>
<verbose mode="enabled"/> <!-- enabled, disabled
-->
Several of your comments are stating the obvious, it's like:

x++ increments the value x contains with one

<DH> <!-- Denavit Hartenberg


Picking a better name would solve that problem. DenavitHartenberg might be
a bit long though.
BTW: don't top post.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jun 1 '06 #4
Thank you! I think description as an attribute is readable. But now I'm
thinking about the order of attributes cause I noticed that for
instance X="0" Y="0" Z="0" set in this order by my script is printed
like X="0" Z="0" Y="0" therefore it could be messy - I wouldn't like
the description to be somewhere between the other attributes. But I
have to test it.

I'll have to consider some better names for the elements

Sending my regards, Anatoli

Jun 1 '06 #5
"an************@googlemail.com" <an************@googlemail.com> wrote:
Thank you! I think description as an attribute is readable. But now I'm
thinking about the order of attributes cause I noticed that for
instance X="0" Y="0" Z="0" set in this order by my script is printed
like X="0" Z="0" Y="0" therefore it could be messy - I wouldn't like
the description to be somewhere between the other attributes. But I
have to test it.


I don't know the library you are using, and also have way more experience
in Perl. I guess that the attributes are stored in a dictionary, which has
no order, and hence the original order of the attributes is lost. In Perl
with some modules I use I can chose to use a list or a hash (=
dictionary). With the former the original order is preserved.

I am sure something like that is possible in Python as well.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jun 1 '06 #6
I use Python/XML packages are xml.dom.minidom and xml.dom.ext (second
just for PrettyPrint)

Jun 1 '06 #7
an************@googlemail.com wrote:
I use Python/XML packages are xml.dom.minidom and xml.dom.ext (second
just for PrettyPrint)


You don't need xml.dom.ext for prettyprint. You can use
doc.toprettyxml()

I gather you want to tweak the prettyprinter to not add the newline
before the comment. The only way to do this is to write your own
printing logic, which is really not that hard, if you just start by
copying the code from .writexml (used by .toprettyxml).

But there's an even easier (if slower) way: pretty print the document,
then parse it in again, remove the text node between the element in
question and the following comment, and then use .writexml() to
serialize it it again.

A few general notes:

* You cannot set the order of attributes in most XML tools, whether
Python or not. This is unfortunate for people who would like to
preserve such details for usability reasons, but that's just the way
XML is. The closest you can get is by using canonicalization [1],
which is available in PyXML as xml.dom.ext.c14n. It just so happens
that canonical XML leaves the attributes in the order you want. You
won't always be so lucky.

* You can always create text nodes by using doc.createTextNode.

* You can always remove text nodes (or any other kind) by using
..removeChild

* It's much easier to navigate if you use XPath. PyXML has an
xml.xpath module you can use.

Good luck.

[1] http://www-128.ibm.com/developerwork...ibrary/x-c14n/

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Jun 4 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
4
by: fowlertrainer | last post by:
Hi ! I want to print, but without newline. I want to create a progress for ftp, but the print is drop a newline for every percent. I want like this: 0% 25% 50% 75% 100% But this happening:...
9
by: Paul Watson | last post by:
I thought that using a comma at the end of a print statement would suppress printing of a newline. Am I misunderstanding this feature? How can I use print and not have a newline appended at the...
12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
2
by: jamesthiele.usenet | last post by:
I recently ran into the issue with 'print' were, as it says on the web page called "Python Gotchas" (http://www.ferg.org/projects/python_gotchas.html): The Python Language Reference Manual says,...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
11
by: A.M | last post by:
Hi, I found print much more flexible that write method. Can I use print instead of file.write method? Thank you,
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
2
by: Phoe6 | last post by:
print and softspace in python In python, whenever you use >>>print statement it will append a newline by default. If you don't want newline to be appended, you got use a comma at the end (>>>print...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.