473,799 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4037
"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>ar mar3</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:

<transformati on 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
-->
<CollisionCheck er type="vcollide"/> <!-- possible values for
type: vcollide, (nyi: disabled) -->
<Visualisatio n 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 "/>
<JointTransform ation>
<RotationAxis X="0" Y="0" Z="1" INIT="0"/>
<TranslationFro mParent X="0" Y="0" Z="0"/>
</JointTransforma tion>
<Visualisatio n> <!-- 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>ar mar3</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:

<transformati on 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:

<transformati on x="0" y="0" z="0" description="so me 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. DenavitHartenbe rg 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 canonicalizatio n [1],
which is available in PyXML as xml.dom.ext.c14 n. 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.createTextN ode.

* 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
4178
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' anything similar you like. Would make my life so much easier. Often I start with a nice and short print statement, then there happen to be more arguments and neat formatting becomes more important and as a result I find myself
4
7214
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: 0%
9
22175
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 end? C:\src\projects\test1>python -c "import sys;print sys.version, 'running on', sys.platform" 2.3.4 (#53, May 25 2004, 21:17:02) running on win32 C:\src\projects\test1>python -c "print 'here'," >jjj
12
2408
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
2920
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: $Revision: 0.0 $
2
5130
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, about the print statement, A "\n" character is written at the end, unless the print statement ends with a comma. What it doesn't say is that if the print statement does end with a
0
1836
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 There is also a wiki page that collects the ideas: http://wiki.python.org/moin/PrintAsFunction There is the will to keep the printing operation very simple for the most common situation, but at the same time to make it flexible (optional no...
11
2080
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
2114
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 improvement. And of course it's possible there's some serious "gotcha" I've overlooked. Thus I welcome any and all comments. If there's some agreement that this proposal is worth further consideration then I'll re-submit a formal document in...
2
11042
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 10,) When, you have a list of characters and want them to be printed together a string using a for loop, there was observation that no matter what there was space coming between the characters. No split or join methods helped. print e, a b c
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10219
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.