SAXand characters

R

remi

Hi,

I don't know if I am in the good newsgroup... Anyway, feel free to
redirect me where it is more relevant.

I am using SAX (with python) to parse a XML file like this one :

<section id="1" name="Nom" description="blabla">
<sousSection id="1" thema="mon thème">
some text here mixed with html code
some lists in html
</sousSection>
<sousSection id="2" thema="thème 2">
another paragraph
</sousSection>

I use characters() method but this one one is called everytime there is
a newline in the text between the <sousSection...> </sousSection> wiwh
seem to be a normal behavior.

How can I have characters method called once and act on the whole
paragraph in "one shot" ?
Thanks for your help.
Rémi.
 
H

Henri Sivonen

remi said:
I use characters() method but this one one is called everytime there is
a newline in the text between the <sousSection...> </sousSection> wiwh
seem to be a normal behavior.
Yes.

How can I have characters method called once and act on the whole
paragraph in "one shot" ?

You need to buffer the characters yourself and not act on them until you
see the next non-characters event.
 
T

Terry Milan

If this paragraph were put in a CDATA section, would he be able to get them
all at once as CDATA?
 
R

remi

Terry Milan a écrit :
If this paragraph were put in a CDATA section, would he be able to get them
all at once as CDATA?

Yes, it is finally what i did. It seems to be fine for now.
Could we say that using CDATA is mandatory if you have "mixed" content
between two tags ?

Here is a part of my XML file :
#------
<section description="description" id="1" name="main title">
<sousSection id="1" thema="titre">
<![CDATA[This text deals with 1 point :
<ol>
<li>point one</li>
<ol>
Here is a web site : <a href="website.fr">http://website.fr</a>]]>
</sousSection>
<sousSection id="2" thema="title2">
#-------
Thanks.
Rémi Boulle.
 
H

Henri Sivonen

Terry Milan said:
If this paragraph were put in a CDATA section, would he be able to get them
all at once as CDATA?

Not reliably. It might appear to work in some situations, but IIRC SAX
doesn't guarantee that the whole chunk of text is reported in one
callback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top