ladon-sevice with CDATA

Asked by romankrv on 2011-08-10

Hi.
I have question about ladon -service.

I create simple function as you have in your example.

But I try use variable which have as CDDATA and get null string from ladon-service.

Can you explane how to work with CDDATA and how is right to take to ladon that variable ?

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
No assignee Edit question
Last query:
2011-08-11
Last reply:
2012-01-08
romankrv (romankrv) said : #1

I think that problem is in here:

soap.py:

def nodeListToDict(nodelist):
 res_dict = {}
 for n in nodelist:
  items = getElementsByTagNameAndDepthNS(n,'*','item',1)
  if len(items):
   res_dict[n.localName.replace('-','_')] = []
   for item in items:
    if len(item.childNodes)==1 and item.childNodes[0].nodeType==n.TEXT_NODE:
     res_dict[n.localName.replace('-','_')] += [getCharacters([item.childNodes[0]])]
    else:
     res_dict[n.localName.replace('-','_')] += [nodeListToDict(item.childNodes)]
  else:
   res_dict[n.localName.replace('-','_')] = getCharacters(n.childNodes)
 return res_dict

here: if len(item.childNodes)==1 and item.childNodes[0].nodeType==n.TEXT_NODE:

I think that one need to add some conditional for CDATA?

Can you fix it?

jsgaarde (jakob-simon-gaarde) said : #2

Hi Romankrv

You are right the soap interface does not handle CDATA, the fix in the bottom should fix the problem, and I have commited it into the sourcetree so that it will be in the next version.

Best Regards
Jakob Simon-Gaarde

=== modified file 'frameworks/python/src/ladon/interfaces/soap.py'
--- frameworks/python/src/ladon/interfaces/soap.py 2011-07-22 20:28:39 +0000
+++ frameworks/python/src/ladon/interfaces/soap.py 2011-08-10 23:10:15 +0000
@@ -9,7 +9,7 @@
 def getCharacters(nodelist):
        raw = PORTABLE_STRING()
        for n in nodelist:
- if n.nodeType == n.TEXT_NODE:
+ if n.nodeType in [n.TEXT_NODE,n.CDATA_SECTION_NODE]:
                        raw += n.data
        return raw

@@ -34,7 +34,7 @@
                if len(items):
                        res_dict[n.localName.replace('-','_')] = []
                        for item in items:
- if len(item.childNodes)==1 and item.childNodes[0].nodeType==n.TEXT_NODE:
+ if len(item.childNodes)==1 and item.childNodes[0].nodeType in [n.TEXT_NODE,n.CDATA_SECTION_NODE]:
                                        res_dict[n.localName.replace('-','_')] += [getCharacters([item.childNodes[0]])]
                                else:
                                        res_dict[n.localName.replace('-','_')] += [nodeListToDict(item.childNodes)]

jsgaarde (jakob-simon-gaarde) said : #3
romankrv (romankrv) said : #4

Can you include that patch to next vercion as bugfix?

thanks

jsgaarde (jakob-simon-gaarde) said : #5

See my answer 9 hours ago ... :-)

jsgaarde (jakob-simon-gaarde) said : #6

Fix commited