473,670 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml.dom.minidom question

I'm using xml.dom.minidom , I get some data by using
obj.getElements ByTagName("name ")[0] then I have an object, but how can I
get the data between the tags ? I could do .toxml() and then strip it
away. But is there a better way maybe a function made for it ?
Also is it possible using the xml.dom.minidom module to create modify an
xml file ?

Jul 18 '05 #1
9 6856

"Geiregat Jonas" <en***@sdf-eu.org> wrote in message
news:3f******** *************** @reader2.news.s kynet.be...
I'm using xml.dom.minidom , I get some data by using
obj.getElements ByTagName("name ")[0] then I have an object, but how can I
get the data between the tags ? I could do .toxml() and then strip it
away. But is there a better way maybe a function made for it ?
Also is it possible using the xml.dom.minidom module to create modify an
xml file ?


Given <name>Greg</name>, 'Greg' is considered an element inside the 'name'
element. So, all you have to do is go one level of elements deeper.

myname = obj.getElements ByTagName("name ")[0].childNodes[0].data
greg
Jul 18 '05 #2
"Greg Krohn" <as*@me.com> writes:
"Geiregat Jonas" <en***@sdf-eu.org> wrote in message
news:3f******** *************** @reader2.news.s kynet.be...
obj.getElements ByTagName("name ")[0] then I have an object, but how can I
get the data between the tags ? I could do .toxml() and then strip it
[...] Given <name>Greg</name>, 'Greg' is considered an element inside the 'name'
element. So, all you have to do is go one level of elements deeper.

myname = obj.getElements ByTagName("name ")[0].childNodes[0].data


Might want to read up about normalization, too.
John
Jul 18 '05 #3
What do you mean by normalization ?

Jul 18 '05 #4
Geiregat Jonas <en***@sdf-eu.org> writes:
What do you mean by normalization ?


Search for the normalize method in here:

http://www.w3.org/TR/DOM-Level-2-Core/core.html
also:

http://www.asptoday.com/catalogue/as...010206_01.html
John
Jul 18 '05 #5
Geiregat Jonas wrote:

What do you mean by normalization ?


http://www.w3.org/TR/REC-xml#AVNormalize
Jul 18 '05 #6
Geiregat Jonas wrote:
What do you mean by normalization ?

Peter Hansen wrote: http://www.w3.org/TR/REC-xml#AVNormalize


Actually, Peter, that link has nothing to do with the normalization of
text nodes in a DOM, which was, I think, the "normalizat ion" in
question.

The link you have provided gives detail on "attribute value
normalization", which is the normalization of whitespace in attribute
values, not DOM text nodes.

Of course, the normalization of test nodes in a DOM is a not a part of
the XML spec, it is a part of the DOM spec.

http://www.w3.org/TR/DOM-Level-2-Core/core.html

Check out the Node.normalize( ) method.

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #7
so What about writing modifying a xml file with minidom ?

Jul 18 '05 #8
Quoting Geiregat Jonas (en***@sdf-eu.org):
But how ???


from xml.dom.minidom import parse

dom = parse(my_xml_fi le)

dom = makeChangesToMy DomTree(dom)

f = open(my_xml_fil e)
f.write(dom.tox ml())

You should verify that this works properly but it should. I remember
at one point observing a problem with a document that declared a DTD,
where the DTD was not preserved and invalid XML was dumped. I don't
remember if minidom was the parser I was using, though, and I don't
have the time to test right now.

--G.

--
Geoff Gerrietts "Me and my homies, we tag O.D.."
<geoff at gerrietts net> --Unknown grafitti artist at a party

Jul 18 '05 #9
"Greg Krohn" <as*@me.com> wrote in message news:<2m******* ***********@new sread3.news.pas .earthlink.net> ...
"Geiregat Jonas" <en***@sdf-eu.org> wrote in message
news:3f******** *************** @reader2.news.s kynet.be...
I'm using xml.dom.minidom , I get some data by using
obj.getElements ByTagName("name ")[0] then I have an object, but how can I
get the data between the tags ? I could do .toxml() and then strip it
away. But is there a better way maybe a function made for it ?
Also is it possible using the xml.dom.minidom module to create modify an
xml file ?


Given <name>Greg</name>, 'Greg' is considered an element inside the 'name'
element. So, all you have to do is go one level of elements deeper.


You mean it's considered a text node inside of the 'name' element
node.

I'll point out that it might actually be more than one text node.
Only safe way is to use the normalize() method.

Better yet, why torture yourself with DOM API, especially when all you
need is to extract data from XML files?

My recommendations would be to use Anobind, Elementtree,
gnosis.xml.obje ctify or 4XPath (an advanage of XPath is that at least
the extraction expression is ross-language):

Anobind:

http://uche.ogbuji.net/tech/4Suite/anobind/
http://www.xml.com/pub/a/2003/08/13/py-xml.html

Elementtree:

http://effbot.org/zone/element-index.htm
http://www.xml.com/pub/a/2003/02/12/py-xml.html

gnosis.xml.obje ctify:

http://www.xml.com/pub/a/2003/07/02/py-xml.html
http://www-106.ibm.com/developerwork...matters11.html

4XPath:

http://uche.ogbuji.net/tech/akara/no...01/basic-xpath
http://www.xml.com/pub/a/2002/10/16/py-xml.html

Good luck.

--Uche
http://uche.ogbuji.net
Jul 18 '05 #10

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

Similar topics

5
2507
by: Paul Miller | last post by:
We've run into minidom's inabilty to handle large (20+MB) XML files, and need a replacement that can handle it. Unfortunately, we're pretty dependent on a DOM, so a pulldom or SAX replacement is likely out of the question for now. Has someone done a more efficient minidom replacement module that we can just drop in? Preferrably written in C?
4
2865
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script") script_node_0.setAttribute("type", "text/javascript") script_node_0.setAttribute("src", "../test.js") minidom renders it as:
0
1907
by: Scott F | last post by:
Hi all, Today's embarassingly simple question goes like this. I have a file, testdoc.xml, to parse. Inside the file is an element <refrain>Yo, Ho, Ho</refrain> So, starting with
4
6060
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using python minidom and everything concerning
2
5977
by: Nick Craig-Wood | last post by:
I'm using xml.minidom to parse some of our XML files. Some of these have entities like "&deg;" in which aren't understood by xml.minidom. These give this error. xml.parsers.expat.ExpatError: undefined entity: line 12, column 1 Does anyone know how to add entities when using xml.minidom? I've spend some time searching the docs/code/google but I haven't found the answer to this question!
1
1634
by: Dean Card | last post by:
I am using minidom to parse a 20,000 line XML file. I have a few instances where the number of child nodes of a particular node can be variable in number. To access them I am doing something like the following... xmldoc = minidom.parseString(r) results = xmldoc.childNodes for myNode in results.childNodes.childNodes: do Stuff with myNode...
4
2011
by: bkamrani | last post by:
Great guys: As a newbie, I'm trying to simply parse a xml file using minidom, but I don't know why I get some extra children(?). I don't know what is wrong in xml file, but I've tried different xml files, still same problem. ****************************************************************************** xml file (fileTest) looks like: <?xml version="1.0" encoding="ISO-8859-1" ?>
1
1969
by: Maksim Kasimov | last post by:
Hi, i'm faced with such a problem when i use xml.dom.minidom: to append all child nodes from "doc" in "_requ" to "doc" in "_resp", i do the following: _requ = minidom.parseString("<resp><doc><one>One</one><two>Two</two></doc></resp>") _resp = minidom.parseString("<resp><doc/></resp>") iSourseTag = _requ.getElementsByTagName('doc') iTargetTag = _resp.getElementsByTagName('doc')
18
758
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i create DOM-object, i get the value of "Data" without "\r\n"
0
1512
by: Gary | last post by:
Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The problem was handled in CVS a while ago. http://mail.python.org/pipermail/xml-sig/2003-October/009904.html
0
8471
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
8386
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
8815
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...
1
8592
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
8661
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
6216
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
4213
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...
1
2802
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
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.