473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

xml.dom.minidom nodeValue returns none

What causes nodeValue to be None?
Im trying to connect to facebook, my lack xml experiance with python is letting me down. Can anyone explain the following?

Expand|Select|Wrap|Line Numbers
  1. def getReply(self, params):
  2.   req = urllib.urlopen(facebook.getURL(params))
  3.   tokenXML = req.read()
  4.   req.close()
  5.   print 'Raw data: ', tokenXML
  6.   return tokenXML
  7.  
  8. tokenXML = parseString(facebook.getReply(params))
  9. token = tokenXML.getElementsByTagName('auth_createToken_response')[0]
  10. print 'toString: ', token
  11. print 'nodeValue: ', token.nodeValue
  12.  
Gives the following:
Expand|Select|Wrap|Line Numbers
  1. C:\Users\simon\Documents\Flash\air\fb++\server>server.py
  2. Raw data:  <?xml version="1.0" encoding="UTF-8"?>
  3. <auth_createToken_response xmlns="http://api.facebook.com/1.0/" xmlns:
  4. xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="ht
  5. tp://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">9
  6. ea0d6592e0f761255e549fbd180443a</auth_createToken_response>
  7.  
  8. toString:  <DOM Element: auth_createToken_response at 0x2335328>
  9. nodeValue:  None
  10.  
Feb 21 '10 #1
5 9892
bvdet
2,851 Expert Mod 2GB
parseString method getElementsByTagName returns a list. The string held between the open and closing tags is a child node that is accessed with element method childNodes. You would access the text between the tags similar to this:
Expand|Select|Wrap|Line Numbers
  1. from xml.dom.minidom import parse, parseString
  2.  
  3. xmlStr = '''<?xml version="1.0" encoding="UTF-8"?>
  4. <auth_createToken_response
  5.  xmlns="http://api.facebook.com/1.0/"
  6.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7.  xsi:schemaLocation="http://api.facebook.com/1.0/facebook.xsd">
  8.  9ea0d6592e0f761255e549fbd180443a
  9. </auth_createToken_response>'''
  10.  
  11. xmlDoc = parseString(xmlStr)
  12. for elem in xmlDoc.getElementsByTagName('auth_createToken_response'):
  13.     for child in elem.childNodes:
  14.         print repr(child.nodeValue.strip())
I formatted the XML string for readability.
Feb 21 '10 #2
bvdet
2,851 Expert Mod 2GB
You can also get the desired result in this case using method firstChild which returns the first child element or None:
Expand|Select|Wrap|Line Numbers
  1. xmlDoc = parseString(xmlStr)
  2. for elem in xmlDoc.getElementsByTagName('auth_createToken_response'):
  3.     child = elem.firstChild
  4.     if child:
  5.         print repr(child.nodeValue.strip())
Feb 21 '10 #3
thanks, is it me or does it make no sense to find it by tagname then have to access it by using childNodes/firstChild.

Thanks for the fast response.
simon
Feb 22 '10 #4
bvdet
2,851 Expert Mod 2GB
A tag can encompass any number of nested elements of different types. A text element (node.nodeType == 3) is just one type of node. When you look at it this way, it makes some sense. Take a look at this XML DOM tutorial.
Feb 22 '10 #5
I get ya, makes sense sort of.
Feb 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roman Yakovenko | last post by:
Hi. What I don't understand is why I dump to xml string that contains new - lines and when I read it from xml new lines replaced by spaces. May be I do something wrong? Or may be I just need to...
0
by: xtian | last post by:
Hi - I'm doing some data conversion with minidom (turning a csv file into a specific xml format), and I've hit a couple of small problems. 1: The output format has a header with some xml that...
5
by: Alexandre | last post by:
Hello all, Could someone explain to me why there is no nextElement in minidom ? if i execute this : *************************************** import xml.dom.minidom doc = """\ <root>...
5
by: Skip Montanaro | last post by:
I'd like to compare two xml.dom.minidom objects, but the naive attempt fails: >>> import xml.dom.minidom >>> d1 = xml.dom.minidom.parse("ES.xml") >>> d2 = xml.dom.minidom.parse("ES.xml") >>> d1...
1
by: Greg Wogan-Browne | last post by:
Hi all, I am having some trouble figuring out what is going on here - is this a bug, or correct behaviour? Basically, when I create an XML document with a namespace using xml.dom.minidom.parse()...
4
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...
0
by: Sullivan WxPyQtKinter | last post by:
Hi, I am now using minidom for my current development. I use cloneNode method in Element object, but it just does not work. The test code is very simple as follows: =========CODE==============...
9
by: Lonnie Princehouse | last post by:
Hi all, I'm getting a seg fault when I try to use minidom to parse some XML inside a wxPython app. I was wondering if someone else could run the simple code below on Linux and, if it doesn't...
13
by: ArseAssassin | last post by:
I'm using minidom to parse XML and to simplify accessing child nodes, I'm trying to implement __getattr__ for the Node class. Yes, I know what most of you will think of that; I'll just have to be...
2
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I've a xml svg file and I would like to update it with Python. First, I would like to fetch one dom node with getElementByID. I've one issue about this method. This is my example : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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
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,...

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.