473,756 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get textual content of a Xml element using 4DOM

Hi all!
I have the following xml file:
"
<items>
<item>hi</item>
<item>hello</item>
</items>
"
and need to read all the content between <items> and </items> tags and
saved in a string, in this case:
"
<item>hi</item>
<item>hello</item>
"
Working with "xml.dom.minido m" I can use the
"xml.dom.minido m.Node.toxml()" to obtain the string inside one node. But
I wish to use 4DOM to load my DOM tree.

Someone know a manner to make something like
"xml.dom.minido m.Node.toxml()" using 4DOM?

Why a lightweight implementation like "xml.dom.minido m" have this
feature, while a 4DOM don't?

Thanks


Jul 18 '05 #1
4 1616
I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
does what you want.

--Uche

Jul 18 '05 #2
I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
does what you want.

[1] http://www.doxdesk.com/software/py/pxdom.html

--Uche

Jul 18 '05 #3
Hi:

PrettyPrint or Print return the value to the console, and i need keep this
value in a string variable to work with it, how can i do this?

thanks to Uche

Frank Abel

-----Original Message-----
From: uc*********@gma il.com
To: py*********@pyt hon.org
Date: 4 Mar 2005 09:23:07 -0800
Subject: Re: get textual content of a Xml element using 4DOM
I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
does what you want.

[1] http://www.doxdesk.com/software/py/pxdom.html

--Uche

--
http://mail.python.org/mailman/listinfo/python-list



Jul 18 '05 #4
Frank Abel Cancio Bello <FRANKA...@esla .cujae.edu.cu> wrote:
PrettyPrint or Print return the value to the console, and i need
keep this value in a string variable to work with it, how can i
do this?


The second parameter to either of these functions can be a stream
object, so you can use a StringIO to get string output:

from StringIO import StringIO
from xml.dom.ext import Print

buf= StringIO()
Print(doc, buf)
xml= buf.getvalue()

--
Andrew Clover
http://www.doxdesk.com/
mailto:an*@doxd esk.com

Jul 18 '05 #5

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

Similar topics

6
9715
by: Dave Kuhlman | last post by:
Suppose that I have content that looks like what I've included at the end of this message. Is there something in the standard Python library that will help me parse it, break into the parts separated by the boundary strings, extract headers from each sub-part, etc? Do I need to add something like the following to the beginning? Content-Type: multipart/related; type="multipart/alternative";
30
3481
by: Reinhold Birkenfeld | last post by:
Hello, I know that there are different YAML engines for Python out there (Syck, PyYaml, more?). Which one do you use, and why? For those of you who don't know what YAML is: visit http://yaml.org/! You will be amazed, and never think of XML again. Well, almost.
1
1663
by: Marlin | last post by:
I am inquiring for a customer of mine who is using XMetal 3.0 as an XML editor. I am trying to add default content to an element so that this content is inserted when the element is inserted. In more detail: When using XMetal to view an XML file in 'tags on' view, you are able to view the attributes and the elements that are allowed within each tag depending on where you are in the document. From here you can select the tag you are...
3
4682
by: Lars G. Svensson | last post by:
Currently, I'm marking up a few pages in German, containing quite some English abbreviations. The abbreviations are marked up as <abbr> with the appropriate title attribute, and -- when appropriate -- I add a "class='initialism'" to tell speach browers to spell it out rather than to read it as one word (Ben Meadowcroft's idea). Simple example: <abbr title="Hypertext Markup Language" class="initialism">HTML</abbr> Now, the point is,...
10
2670
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be cross-browser support.for IE (5-6) and browsers derived from Mozilla (varies). Thank you... <%= Clinton Gallagher
2
5255
by: rpesq | last post by:
Hi, I Need help changing the content of a DIV. I sincerely researched the issue and have not found a solution except to scrap the idea and stick with the iframe code that I had been using. My purpose here is to avoid iframes. I know how to change the DIV content to other basic html statements, such as basic IMG's or Lists, but I want to put a Javascript into the DIV, and have not found a way to do it.
4
4126
by: Mike [MCP VB] | last post by:
Hi, I hope this is the right place to ask. I have an xml file thus: <?xml version="1.0" encoding="UTF-8"?> <Message xmlns="urn:myurl-org:ns2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:myurl-org:ns2 ...\Schemas\schema.xsd" type="Message"> <id root="7DC0FFE7-1224-4598-8F20-3B7662D416A1"/>
8
5911
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
1
1935
by: mahesh.kanakaraj | last post by:
Hi All, I have a confusion in finding the 'effective content' of a complex type definition in a XML Schema. I shall give you an example situation to clearly explain my problem. Let's have an element declaration as follows:
0
10034
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...
0
9872
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 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...
0
9713
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...
0
8713
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 projectplanning, coding, testing, and deploymentwithout 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...
1
7248
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
6534
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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
3
2666
bsmnconsultancy
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...

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.