[reportlab-users] pyRXP CDATA sections

Robin Becker reportlab-users@reportlab.com
Mon, 19 May 2003 11:13:48 +0100


This person wants to indicate CDATA sections in the pyRXP output. Seems
somewhat strange to me, but others may feel differently. It is only
another flag which we can leave turned off by default.

Anyone with 0.02euros to offer?

-----Original Message-----
From: reportlab-info-admin@www.reportlab.co.uk
[mailto:reportlab-info-admin@www.reportlab.co.uk]On Behalf Of Max
Neunhoeffer
Sent: 18 May 2003 17:41
To: info@reportlab.com
Subject: [reportlab-info] Message for the author of pyRXP
>
>
Dear info@reportlab.com!
>
Could you please forward this message to the author of pyRXP, because
I could not find his name or email anywhere.
>
Dear author of pyRXP!
>
I made the modification in the following patch file to pyRXP, because
I wanted to be able to read in and parse an XML document and write
it out again in Python. The problem was that CDATA sections were
not marked. I found it convenient to have a switch in pyRXP to make
CDATA sections appear as elements with type "<![CDATA[", empty
attribute dictionary and a single string in the list of children.
>
Perhaps you like this modification or at least you have one more vote
for any change which solves the above mentioned problem.
>
Best regards,
  Max Neunhoeffer
>
Index: pyRXP.c
===================================================================
RCS file: /cvsroot/reportlab/rl_addons/pyRXP/pyRXP.c,v
retrieving revision 1.21
diff -r1.21 pyRXP.c
56a57
> static PyObject *CDATATagName;
84a86
>     CDATATagName    special tagname used for CDATA sections\n\
214a217,220
>         ReturnCDATASectionsAsTuples = 0\n\
>             If this is on, the parser returns for each CDATA
section a tuple\n\
>             with name field equal to CDATATagName containing a
single string\n\
>             in its third field that is the CDATA section.\n\
256a263
>         {"ReturnCDATASectionsAsTuples",0},
262a270
> #define ReturnCDATASectionsAsTuples
(ParserFlag)(1+(int)ReturnProcessingInstructions)
447,449c455,469
<                       t = PYSTRING(bit->cdsect_chars);
<                       PyList_Append(PDGetItem(stack[*depth],2),t);
<                       Py_DECREF(t);
---
>
if(ParserGetFlag(p,ReturnCDATASectionsAsTuples)){
>                             t = _makeNodePD( pd, CDATATagName,
Py_None, 0);
>                           if(pd->fourth==recordLocation)
_reverseSrcInfoTuple(PyTuple_GET_ITEM(t,3));
>                             Py_INCREF(CDATATagName);
>                             Py_INCREF(Py_None);
>                             s = PYSTRING(bit->cdsect_chars);
>                             PyList_Append(PDGetItem(t,2),s);
>                             Py_DECREF(s);
>                           PyList_Append(PDGetItem(stack[*depth],2),t);
>                           Py_DECREF(t);
>                         } else {
>                             t = PYSTRING(bit->cdsect_chars);
>                             PyList_Append(PDGetItem(stack[*depth],2),t
);
>                           Py_DECREF(t);
>                         }
534c554
<       return n!=piTagName && n!=commentTagName;
---
>       return n!=piTagName && n!=commentTagName && n!=CDATATagName;
905a926,927
>         CDATATagName = PYSTRING8("<![CDATA[");
>         PyDict_SetItemString(d, "CDATATagName", CDATATagName );
--
   //  //   Max Neunhöffer <max.neunhoeffer@math.rwth-aachen.de>
  //  //   Alexianergraben 4-6, 52062 Aachen, Germany
 //  //   Tel.: +49 241 406605 (private) / +49 241 8094550 (institute)
//  //   May the Source be with you!
>
-- 
Robin Becker