I've been searching high and low for a way to simply convert a small
XML configuration file to Python data structures. I came across gnosis
XML tools, but need a built-in option for doing something similar.
My knowledge of DOM and anything beyond simple XML structures is
rudimentary at best. Is there a simple way to use SAX handlers to pull
attributes and elements into Python lists/dictionaries? 19 3296
Amara does indeed make it effortless to transform an XML document into
a Python structure. Unfortunately this suggestion requires the 3rd
party software, Amara, _and_ a 4Suite installation according to the
website.
The reason I can't expect users to have 3rd party tools is because this
tool will be used in a secure lab environment without Internet access.
Asking the admins to place these software packages on the network for
users to install is like asking GW to say something semi-intelligent. ga********@gmai l.com wrote: Amara does indeed make it effortless to transform an XML document into a Python structure. Unfortunately this suggestion requires the 3rd party software, Amara, _and_ a 4Suite installation according to the website.
The reason I can't expect users to have 3rd party tools is because this tool will be used in a secure lab environment without Internet access. Asking the admins to place these software packages on the network for users to install is like asking GW to say something semi-intelligent.
Why not use distutils to install any additional packages you need? That's
what it's there for. Presumably you're going to need to package this thing
for distribution anyway.
--
Website: www DOT jarmania FULLSTOP com
A good question... Here's a followup question:
Does third-party software compile as well as the built-in modules when
using distutils and the py2exe extension module?
Am Wed, 16 Mar 2005 14:19:49 -0800 schrieb ga********@gmai l.com: I've been searching high and low for a way to simply convert a small XML configuration file to Python data structures. I came across gnosis XML tools, but need a built-in option for doing something similar.
My knowledge of DOM and anything beyond simple XML structures is rudimentary at best. Is there a simple way to use SAX handlers to pull attributes and elements into Python lists/dictionaries?
Hi,
Just write a script which uses xml.sax. It is not difficult.
You get an event for every start-tag and for every end-tag.
The class which handles the events can build the structure
if your XML file.
The online version of the python cookbook has some
python and SAX examples,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
"ga********@gma il.com" wrote: I've been searching high and low for a way to simply convert a small XML configuration file to Python data structures. I came across gnosis XML tools, but need a built-in option for doing something similar.
My knowledge of DOM and anything beyond simple XML structures is rudimentary at best. Is there a simple way to use SAX handlers to pull attributes and elements into Python lists/dictionaries?
tools like ElementTree and xmltramp are very easy to use. ElementTree builds
a tree of Element objects which behave like lists (of subelements) and contain
dictionaries (of attributes). xmltramp builds a tree where both subelements and
attributes are mapped to object attributes. http://www.aaronsw.com/2002/xmltramp/ http://www.effbot.org/zone/element-index.htm
if you want to ship any of them with your application, you only need a single
module (xmltramp.py and ElementTree.py, respectively).
API summaries: http://reagle.org/joseph/blog/techno...menttree-model http://reagle.org/joseph/blog/techno...xmltramp-model
(xmltramp might be a bit easier to use for simple cases, elementtree is a bit more
flexible and a bit more efficient, especially if you're using the C implementation)
</F>
Lutz Horn wrote: ga********@gmai l.com schrieb:
I've been searching high and low for a way to simply convert a small XML configuration file to Python data structures.
Take a look at Amara (http://uche.ogbuji.net/tech/4Suite/amara/).
Lutz
Amara rules xml to python conversions. I've used it successfully for an
xml interface to legacy databases.
Huy
Since I've exhausted every option except for Amara, I've decided to
give it a try. However, this will only work if I can compile Amara and
4suite along with my application. I doubt 4suite will be able to be
compiled, but I'll try it anyway.
If I weren't set on using XML (I know, not every application requires
it and it's abused), I would probably go with a simpler format like an
INI file or YAML. The requirement that leads me to use XML for a
simple config file is that the rest of this project already utilizes
XML and another developer must integrate his NetBeans GUI with my app
and config file. Not to mention that this must be across Linux and
Windows platforms. To make this easier on everyone else, I'm using a
simple XML schema that I know everyone can write to. As far as I know,
YAML isn't easily written to from a Java class and an INI file isn't
very popular on the Linux side. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: chris |
last post by:
Hi,
After going back through the XSL tutorials and the help here I have
largely solved the problem of merging two XHTML files, but one small
detail remains...
The parser outputs
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
by: dSchwartz |
last post by:
I'm creating xml files from a dataset:
myDataSet.WriteXml(m_XmlFile, XmlWriteMode.IgnoreSchema);
and saving them to disk. Then i want to use the Xml control to format
this xml with xsl stylesheet. here is part of my xml file created by
the line above:
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<articles>
|
by: John Estess |
last post by:
The following xml file is converted by the piece of xml below (oil.xsl).
I have the right number of dots for the unordered list items, but it
won't print out the "use's". What am I doing wrong?
XML scrap:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="oil.xsl"?>
<oils>
|
by: lars |
last post by:
I would expected that the stylesheet below would tag the
contents of the element "Date" with <b> and </b>, but it doesn't,
at least not with xsltproc. It just passes the content through
unchanged.
I've also tried diffent permutations of upper and lower case.
What have I missed?
-Lars
|
by: Tony G |
last post by:
Hi -
My experience with XML is limitted although I understand the basics,
and I just recently for the first time created an XML document from a
database query and styled it successfully with CSS.
I have the DTD and the XML included in one document, and the style
sheet is linked to.
(I would cut and paste the text here - but the damn server is down due
to the general incompetence of our network team and I have not backed
| |
by: Randy |
last post by:
Is there a dotnet class that formats XML simple types. I'm making a
xmldocument which has a timestamp element (among others). The format is:
yyyy-MM-ddThh:mm:ss (which looks like 2003-09-28T07:55:06).
The schema looks like:
<xsd:simpleType name="TimestampType">
<xsd:annotation>
<xsd:documentation>Base typefor a date and time stamp</xsd:documentation>
</xsd:annotation>
|
by: Mark Jerde |
last post by:
We have developed about 80 XML documents, each probably 150 lines long, that
are all supposed to conform to a schema. My understanding is the way to
show that an XML document conforms to a schema is to include a reference to
the XSD in the XML document, and check that it is valid.
Some other members of the project team don't want to include a reference to
the XSD in the XML documents, citing possible differences in parsers.
Is my...
|
by: MSSQLServerDeveloper |
last post by:
I have the following xml file -
<?xml version="1.0" encoding="utf-8" ?>
<Publisher1>Mary</Publisher1>
<Distributor>Joe</Distributor>
and snippet of vb.net code that is failing with the error-
"The <Publisher1> tag from namespace is not expected"
Dim XmlReader As New XmlTextReader("ReplConfig.xml")
Return XmlReader.ReadElementString("Distributor")
|
by: shailesh333 |
last post by:
I have a simple xsd file with me.
How do I create xml instance of this xsd file.
|
by: whitep8 |
last post by:
Hi all,
im a little bit puzzled with this one.
Im after creating a simplexml encoded file using php, which calls from a mysql database.
i have the following, but i dont see what is wrong with the syntax.
<?php
|
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: 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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |