473,503 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Elementtree tag

I have a another question...

using elementtree, is there a proper way to get at the data
'123456789' in this tag?

'<id 123456789 />'

I tried making it an element, but the only attribute that returns
anything is the "tag" attribute. Does that section of a tag have any
proper name that I'm missing? Or is it just bad XML style?

Thanks!

~Sean
Dec 14 '07 #1
2 1178
On Dec 13, 7:52 pm, Sean DiZazzo <half.ital...@gmail.comwrote:
I have a another question...

using elementtree, is there a proper way to get at the data
'123456789' in this tag?

'<id 123456789 />'

I tried making it an element, but the only attribute that returns
anything is the "tag" attribute. Does that section of a tag have any
proper name that I'm missing? Or is it just bad XML style?
It is not even legal xml.
This may work.
>>from xml.etree import ElementTree as ET
elm = ET.fromstring('<atag id="123456789" />')
elm
<Element atag at 1ba2f80>
>>elm.attrib
{'id': '123456789'}
>>>

Dec 14 '07 #2
On Dec 13, 8:46 pm, Waldemar Osuch <waldemar.os...@gmail.comwrote:
On Dec 13, 7:52 pm, Sean DiZazzo <half.ital...@gmail.comwrote:I have a another question...
using elementtree, is there a proper way to get at the data
'123456789' in this tag?
'<id 123456789 />'
I tried making it an element, but the only attribute that returns
anything is the "tag" attribute. Does that section of a tag have any
proper name that I'm missing? Or is it just bad XML style?

It is not even legal xml.
This may work.
>from xml.etree import ElementTree as ET
elm = ET.fromstring('<atag id="123456789" />')
elm

<Element atag at 1ba2f80>
>elm.attrib
{'id': '123456789'}
Thanks. I was afraid of that. Yet another hack for my code. argggh
Dec 14 '07 #3

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

Similar topics

7
3244
by: Stewart Midwinter | last post by:
I want to parse a file with ElementTree. My file has the following format: <!-- file population.xml --> <?xml version='1.0' encoding='utf-8'?> <population> <person><name="joe" sex="male"...
1
3070
by: Greg Wilson | last post by:
I'm trying to convert from minidom to ElementTree for handling XML, and am having trouble with entities in DTDs. My Python script looks like this: ...
3
3937
by: mirandacascade | last post by:
Verion of Python: 2.4 O/S: Windows XP ElementTree resides in the c:\python24\lib\site-packages\elementtree\ folder When a string that does not contain well-formed XML is passed as an argument...
1
3036
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
15
5395
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
0
1746
by: Greg Aumann | last post by:
I am trying to write some python code for a library that reads an XML-like language from a file into elementtree data structures. Then I want to be able to read and/or modify the structure and then...
2
1954
by: mirandacascade | last post by:
Situation is this: 1) I have inherited some python code that accepts a string object, the contents of which is an XML document, and produces a data structure that represents some of the content of...
5
9974
by: saif.shakeel | last post by:
#!/usr/bin/env python from elementtree import ElementTree as Element tree = et.parse("testxml.xml") for t in tree.getiterator("SERVICEPARAMETER"): if t.get("Semantics") == "localId":...
1
294
by: Mike Slinn | last post by:
The following short Python program parses a KML file and displays the names of all Marks and Routes: from elementtree.ElementTree import ElementTree tree = ElementTree(file='test.kml') kml =...
3
2075
by: gray.bowman | last post by:
I'm messing around with trying to write an xml file using xml.etree.ElementTree. All the examples on the internet show the use of ElementTree.write(), although when I try to use it it's not...
0
7083
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
7278
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
7328
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
7456
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
5578
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
4672
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...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
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 ...
0
379
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...

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.