Hi. Does anyone know of a module that will take a suitable Python
dictionary and return the corresponding XML structure?
In Perl I use XML::Simple's handy XMLout function:
use XML::Simple 'XMLout';
my %h = ( 'Foo' =+{
'Bar' =+{
'Baz' =[ { 'meenie' =3 },
{ 'meenie' =7 } ],
'eenie' =4,
},
'minie' =1,
'moe' =2,
} );
print XMLout( \%h, KeepRoot =1, KeyAttr =undef );
__END__
<Foo minie="1" moe="2">
<Bar eenie="4">
<Baz meenie="3" />
<Baz meenie="7" />
</Bar>
</Foo>
Is there a Python module that can do a similar conversion from
a Python dict to an XML string?
(FWIW, I'm familiar with xml.marshal.gen eric.dumps, but it does
not produce an output anywhere similar to the one illustrated
above.)
TIA!
Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded. 3 1654
kj wrote:
Hi. Does anyone know of a module that will take a suitable Python
dictionary and return the corresponding XML structure?
In Perl I use XML::Simple's handy XMLout function:
use XML::Simple 'XMLout';
my %h = ( 'Foo' =+{
'Bar' =+{
'Baz' =[ { 'meenie' =3 },
{ 'meenie' =7 } ],
'eenie' =4,
},
'minie' =1,
'moe' =2,
} );
print XMLout( \%h, KeepRoot =1, KeyAttr =undef );
__END__
<Foo minie="1" moe="2">
<Bar eenie="4">
<Baz meenie="3" />
<Baz meenie="7" />
</Bar>
</Foo>
Is there a Python module that can do a similar conversion from
a Python dict to an XML string?
This is so trivial to do in ElementTree that I wouldn't expect there to be a
special package for this. If you write the estimated 15 lines of code
yourself, you can even tweak it into exactly the structure you want.
Stefan
On Jun 20, 1:37*pm, kj <so...@987jk.co m.invalidwrote:
Hi. *Does anyone know of a module that will take a suitable Python
dictionary and return the corresponding XML structure?
In Perl I use XML::Simple's handy XMLout function:
* use XML::Simple 'XMLout';
* my %h = ( 'Foo' =+{
* * * * * * * * * * * * 'Bar' =+{
* * * * * * * * * * * * * * * * * * 'Baz' =[ { 'meenie' =3 },
* * * * * * * * * * * * * * * * * * * * * * * *{ 'meenie' =7 } ],
* * * * * * * * * * * * * * * * * * 'eenie' =4,
* * * * * * * * * * * * * * * * * },
* * * * * * * * * * * * 'minie' =1,
* * * * * * * * * * * * 'moe' =2,
* * * * * * * * * * * } );
* print XMLout( \%h, KeepRoot =1, KeyAttr =undef );
* __END__
<Foo minie="1" moe="2">
* <Bar eenie="4">
* * <Baz meenie="3" />
* * <Baz meenie="7" />
* </Bar>
</Foo>
Is there a Python module that can do a similar conversion from
a Python dict to an XML string?
(FWIW, I'm familiar with xml.marshal.gen eric.dumps, but it does
not produce an output anywhere similar to the one illustrated
above.)
TIA!
Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Try: http://pyxml.sourceforge.net/topics/howto/node26.html
- Paddy.
On Jun 20, 6:37*am, kj <so...@987jk.co m.invalidwrote:
Hi. *Does anyone know of a module that will take a suitable Python
dictionary and return the corresponding XML structure?
In Perl I use XML::Simple's handy XMLout function:
* use XML::Simple 'XMLout';
* my %h = ( 'Foo' =+{
* * * * * * * * * * * * 'Bar' =+{
* * * * * * * * * * * * * * * * * * 'Baz' =[ { 'meenie' =3 },
* * * * * * * * * * * * * * * * * * * * * * * *{ 'meenie' =7 } ],
* * * * * * * * * * * * * * * * * * 'eenie' =4,
* * * * * * * * * * * * * * * * * },
* * * * * * * * * * * * 'minie' =1,
* * * * * * * * * * * * 'moe' =2,
* * * * * * * * * * * } );
* print XMLout( \%h, KeepRoot =1, KeyAttr =undef );
* __END__
<Foo minie="1" moe="2">
* <Bar eenie="4">
* * <Baz meenie="3" />
* * <Baz meenie="7" />
* </Bar>
</Foo>
Is there a Python module that can do a similar conversion from
a Python dict to an XML string?
(FWIW, I'm familiar with xml.marshal.gen eric.dumps, but it does
not produce an output anywhere similar to the one illustrated
above.)
What about
-----------------------------------------
import lxml.etree as ET
from lxml.builder import E
h = E.Foo(
dict(minie='1', moe='2'),
E.Bar(
dict(eenie='4') ,
E.Baz(meenie='3 '),
E.Baz(meenie='7 ')))
print ET.tostring(h, pretty_print=Tr ue)
----------------------------------------
<Foo moe="2" minie="1">
<Bar eenie="4">
<Baz meenie="3"/>
<Baz meenie="7"/>
</Bar>
</Foo>
---------------------------------------
Waldemar This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jon Rea |
last post by:
is there a c# -> c++ code converter out there ?
Hi people,
I was just wondering if there is a C# to C++ converter out there. I have
some working c# code and need to integrate it into a non-managed c++
program. The classes used are all user defined and use simple floats ints
etc, so its just a matter of converting syntax and adding proper pointers. A
converter program would therefore save me a lot of time ...
|
by: matty.hall |
last post by:
I have two classes: a base class (BaseClass) and a class deriving from
it (DerivedClass). I have a List<DerivedClass> that for various
reasons needs to be of that type, and not a List<BaseClass>. However, I
need to cast that list to a List<BaseClass> and it is not working. The
code is below. I get the following exception:
"Unable to cast object of type 'System.Collections.Generic.List`1' to
type 'System.Collections.Generic.List`1'."
...
|
by: karch |
last post by:
I am beginning to write my first applications with C++/CLI and was wondering
if someone could demonstrate the proper way to convert a sample piece of
code. I just need some help understanding the new syntax for handles and
iterating, etc. Thanks in advance for the help.
SoapFormatter formatter = new SoapFormatter();
byte buffer = new byte;
MemoryStream stream = new MemoryStream(buffer);
foreach (object o in dept) {
|
by: karch |
last post by:
Thanks to everyone who has helped with some of my elementary questions about
C++/CLI equivalents to C#. I have a few more items that are giving me
headaches. All help is appreciated. What is the proper way to convert the
following?
1) data.ForEach(delegate(int num)
{ formatter->Serialize(stream, num); } );
(basically how are delegates implemented in C++/CLI)
|
by: Sam |
last post by:
Hi,
I've seen this kind of thing in C# quite often :
cbo.Validating += new CancelEventHandler(cbo_Validating);
what is the vb.net equivalent ?
Please don't send me to
http://www.developerfusion.com/utilities/convertcsharptovb.aspx
I've already tried this and it's not translating properly.
Thx
| |
by: Maury |
last post by:
Do you know if somewhere exists the conversione of
Vb.Net 'My' class
(or better My.Computer.Network.Ping)
in C Sharp?
Thanks
M.A.
|
by: Andrew |
last post by:
One year ago I have programmed in VB. There was a function named
"InStrRev".
In C# I don't have found a similar function. Can anybody help me in
this question.
Thanks a lot
regards
andrew
|
by: py_genetic |
last post by:
Hello,
I'm importing large text files of data using csv. I would like to add
some more auto sensing abilities. I'm considing sampling the data
file and doing some fuzzy logic scoring on the attributes (colls in a
data base/ csv file, eg. height weight income etc.) to determine the
most efficient 'type' to convert the attribute coll into for further
processing and efficient storage...
Example row from sampled file data: , ....]
|
by: Soren |
last post by:
Hi,
I want to control some motors using the parallel port.. however, my
laptop does not have any parallel ports (very few do). What I do have
is a USB->Parallel converter... I thought about using PyParallel, but
the USB->Parallel converter doesn't actually map to the LPT port ..
and PyParallel only looks for LPT ports?
Has anyone tried doing this? What are my options for controlling
parallel connections on a laptop with no parallel...
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |