473,624 Members | 2,629 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">CatalogEx ample</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 1449
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.l ength)]

--
Andrew Clover
mailto:an*@doxd esk.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">CatalogEx ample</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="mynam espace" me:ref="#busine ss.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
1778
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 up dynamically at runtime' (Quoting "Learning Python", 2nd. ed., p367). It seems to me that two good conventions are to (1) initialize all attributes in the __init__ function (2) avoid creating new attributes elsewhere that are not initialized...
8
2410
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. Generally, the documentation suggests that queues or similar constructs should be used for thread inter-process comms. I've had a lot of success in doing that (generally by passing in the queue during the __init__ of the thread) and I can see...
1
2719
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 namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
7
1843
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
3488
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" substitutionGroup="CC"/> The code: while (reader->Read()) {
8
1673
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 variables. In fact, all my variables are referencing to objects of the same type. Can anyone suggest me a way to get this list of variables ? Thanks
1
1640
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." http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-84CF096 The question I have is if such NamedNodeMap contains the specified attributes or all possible/actual/specified attributes. This question is important because MSIE 6 will return all possible...
28
1462
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? Thanks, Alan Isaac
2
2135
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 class Book: total # is a class attribute
26
1892
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. With ipython, I use tab completion all the time, but I can rarely tell from the names alone whether it is an attribute or method. Tips? Ideas? Best practices?
0
8249
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
8179
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
8685
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...
1
8348
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
7176
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, and deployment—without 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
6112
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
5570
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
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1493
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.