Re: Problem with pyXML DOM

2005-05-04 Thread Maniac
Florian Lindner wrote:

Traceback (most recent call last):
  File ConfigReader.py, line 40, in ?
c = ConfigReader(f)
  File ConfigReader.py, line 32, in __init__
print sourceNode.getElementsByTagName(filename)[0].nodeValue()
TypeError: 'NoneType' object is not callable
  

This is because nodeValue here is 'None' and 'None()' doesn't make 
sense. Looks like you want the thing between filename and /filename. 
This is not a nodeValue, this is nodeValue of firstChild of element 
'filename'. So this should work:

print sourceNode.getElementsByTagName(filename)[0].firstChild.nodeValue
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with pyXML DOM

2005-05-04 Thread Florian Lindner
Maniac wrote:

 Florian Lindner wrote:
 
Traceback (most recent call last):
  File ConfigReader.py, line 40, in ?
c = ConfigReader(f)
  File ConfigReader.py, line 32, in __init__
print sourceNode.getElementsByTagName(filename)[0].nodeValue()
TypeError: 'NoneType' object is not callable
  

 This is because nodeValue here is 'None' and 'None()' doesn't make
 sense. Looks like you want the thing between filename and /filename.
 This is not a nodeValue, this is nodeValue of firstChild of element
 'filename'. So this should work:
 
 print sourceNode.getElementsByTagName(filename)[0].firstChild.nodeValue

Ok, works perfect. Thanks!

But I don't really understand the logic:

given I have the node A

filenamepath/filename

A.firstChild.nodeValue == path

How would the second child of A look like? (ok, None in this case) How would
a XML fragment look like that has a second child?

What would be the nodeValue of A?

for me a child of a node is something like

filename
  child1 /
  child2 /
/filename


Thanks,

Florian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with pyXML DOM

2005-05-04 Thread Maniac
Florian Lindner wrote:

But I don't really understand the logic:

given I have the node A

filenamepath/filename

A.firstChild.nodeValue == path

How would the second child of A look like? (ok, None in this case)

Yes. It's actually required by DOM standard: NodeList (which is returned 
from getElementsByTagName) should return 'null' (None in Python) on 
unknown index: 
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-844377136

 How would
a XML fragment look like that has a second child?
  

Like this for example:
filenamechild/child//filename

or like this:

filenameI'm a text child node ElementChildNode//filename

What would be the nodeValue of A?
  

It's not related to children. There are several types of nodes: 
documents, elements, text, comments, processing instructions (things in 
??)... Their nodeValue depends on their nature.
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-844377136

for me a child of a node is something like

filename
  child1 /
  child2 /
/filename
  

Almost :-). Here filename has actually 5 nodes:
1. text node '\n  '
2. element node 'child'
3. text node '\n  '
4. element node 'child'
5. text node '\n'

In other words: in DOM whitespace counts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with pyXML DOM

2005-05-04 Thread Florian Lindner
Hello,
I'm using the PyXML Package.

My XML document looks like that:

visConf
graph name=testgraph1 type=chart
source type=CSV
filename/home/florian/visualizer/testdata.csv/filename
/source

/graph
/visConf

print sourceNode.getElementsByTagName(filename)[0]
print sourceNode.getElementsByTagName(filename)[0].nodeValue()

gives:

Element Node at b7af74ac: Name='filename' with 0 attributes and 1 children

Traceback (most recent call last):
  File ConfigReader.py, line 40, in ?
c = ConfigReader(f)
  File ConfigReader.py, line 32, in __init__
print sourceNode.getElementsByTagName(filename)[0].nodeValue()
TypeError: 'NoneType' object is not callable

Given only the first call everything seems fine, I have a Node object for
the filename.
But why does the second call fails?

The documentationhttp://pyxml.sourceforge.net/topics/howto/node20.html says:


nodeValue
Value of this node. For some types of node, such as Text nodes, the value is
a string containing a chunk of textual data; for others, such as Text, the
value is just None.

Which I don't really understand? What is differencee between the two text
nodes??

Thanks,

Florian
-- 
http://mail.python.org/mailman/listinfo/python-list