473,406 Members | 2,439 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,406 software developers and data experts.

writing xml tree

I am doing my first work in python/xml

Is is possiable to write a xmlTree in a single command?
for example

doc = libxml2.parseFile (filename)
# add node to doc

doc.write(filename) ??????????????

I have seen several examles writing one element or line at a time, but never
the whole tree.

Thanks
Dave Farning

Jul 18 '05 #1
1 2564
david farning <df******@localhost.localdomain> wrote in message news:<Pz********************@newssrv26.news.prodig y.com>...
I am doing my first work in python/xml

Is is possiable to write a xmlTree in a single command?
for example

doc = libxml2.parseFile (filename)
# add node to doc

doc.write(filename) ??????????????

I have seen several examles writing one element or line at a time, but never
the whole tree.


You can use the serialize method on the document node to get the
document as text (or on any other node to get a document fragment as
text):

s = doc.serialize()
# Use normal file writing mechanisms.

Or you could use the saveFile method to write to a file:

doc.saveFile(filename)

I'd recommend using Python interactively to see which methods are
available on the document node:

import libxml2
doc = libxml2.parseFile(filename)
dir(doc)

Indeed, until I started responding to your question, I hadn't noticed
saveFile, so there's a lot to discover. ;-)

Paul
Jul 18 '05 #2

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

Similar topics

0
by: paul b | last post by:
Hello, I am writing some LDAP-scripts in PHP. One of the scripts has to add new objects(urls) to the tree using the ldap_add command. The problem is that I cannot add objects of the type...
2
by: Troy Lynch | last post by:
I'm looking into writing a Category Hierarchy on a site I've written and am looking for some information about writing this kind of code. Maybe some samples or a book. Any information would be...
2
by: Prashanth Ellina | last post by:
Hi, I need to write some data to an xml file. I have an XML Schema defined. I would like to use some mechanism of writing the data to the xml file and having exceptions thrown back to me when...
6
by: DanielEKFA | last post by:
Hey there :) I was once told that the STL classes had member functions to write their data to disk and to restore that data. Searching google (and why are there no "stl" or "map" manpages?), it...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
5
by: Robert Gale | last post by:
I am writing an RSS reader in C# and I'm trying to write the contents of a TreeView to an XML file. I have tried using XmlWriter and have managed to write simple tree structures but I get confused...
10
by: Magnus Lycka | last post by:
We're using DOM to create XML files that describes fairly complex calculations. The XML is structured as a big tree, where elements in the beginning have values that depend on other values further...
2
by: kaustubh.deo | last post by:
Hello, Need your valuable inputs for this scenario. Any pointers would be helpful. I have large data set (few 100s of MB or sometimes may even go up to GB). I populate a DOM tree using this...
4
by: Arengin | last post by:
HI everyone, I am new with Xerces-C but I managed to get a DOMTree runing and to extracte the data to the screen. However I need to write the Tree back to a file.... and this is where I am stuck. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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...
0
agi2029
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,...
0
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...

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.