473,499 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml attributes question

hi!

i am trying to print the keys of a NamedNodeMap which contains the
attributes of a element.
for the element,
<DATA ref="#business.name">CatalogExample</DATA>

i expect
attribs = plist[0].attributes
attribs.keys()
to print "ref" #plist[0] is the data element shown above
It however prints the following
[(None, u'ref')]

why?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
2 1440
Ajay <ab******@mail.usyd.edu.au> wrote:
attribs.keys() [(None, u'ref')] why?


Namespace-aware DOM implementations index attributes by the localName
*and* their namespaceURI. The 'ref' attribute isn't in a namespace
(signified by 'None') so this should be part of the key to support eg.
getAttributeNS efficiently.

Don't rely on the Python-style dictionary methods like keys() when you
are handling a NamedNodeMap. The Python DOM bindings do not guarantee
that it exists, or what it returns if it does. 4DOM behaves
differently to minidom as you can see; other implementations are
different again. Further, the results of keys(), values() and items()
are inconsistent even within single implementations.

Sticking to the standard DOM methods, one could say:

keys= [attribs.item(i).name for i in range(attribs.length)]

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #2
On Sun, 15 Aug 2004 12:25:58 +1000, Ajay wrote:
hi!

i am trying to print the keys of a NamedNodeMap which contains the
attributes of a element.
for the element,
<DATA ref="#business.name">CatalogExample</DATA>

i expect
attribs = plist[0].attributes
attribs.keys()
to print "ref" #plist[0] is the data element shown above It however prints
the following
[(None, u'ref')]

why?


because of xml namespaces. Any xml element / attribute is fully
caracterized by it's name and the namespace it belongs to. None is used to
represent the empty namespace. With the following element :

<DATA xmlns:me="mynamespace" me:ref="#business.name">...</DATA>

your sample code would have printed :
[(u'mynamespace', u'ref')]
--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #3

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

Similar topics

6
1774
by: beliavsky | last post by:
I have started using classes with Python and have a question about their use. In Python, 'attributes are all "public" and "virtual" in C++ terms; they're all accessible everywhere and all looked...
8
2406
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. ...
1
2698
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
7
1822
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
6
3479
by: Developer | last post by:
Hello, I'm experimenting with and XmlTextReader sample, and don't understand how the attributes are being processed. Here's the input: <xsd:element name="AA" type="BB"...
8
1667
by: Thomas Girod | last post by:
Hi there. I'm trying to get a list of attributes from a class. The dir() function seems to be convenient, but unfortunately it lists to much - i don't need the methods, neither the built-in...
1
1629
by: Gérard Talbot | last post by:
Hello, According to DOM 2 Core, the attribute "nodeRef.attributes" is "A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise."...
28
1446
by: Alan Isaac | last post by:
I have a class whose instances should only receive attribute assignments for attributes that were created at inititialization. If slots are not appropriate, what is the Pythonic design for this? ...
2
2128
by: james_027 | last post by:
hi everyone, I am now in chapter 5 of Dive Into Python and I have some question about it. From what I understand in the book is you define class attributes & data attributes like this in python...
26
1878
by: tjhnson | last post by:
Hi, With properties, attributes and methods seem very similar. I was wondering what techniques people use to give clues to end users as to which 'things' are methods and which are attributes. ...
0
7134
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,...
0
7180
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,...
1
6905
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
7395
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
5485
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
4609
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
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
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.